Jquery 发送前的Ajax Post功能不起作用
在发送函数之前我不知道如何写 以下代码Jquery 发送前的Ajax Post功能不起作用,jquery,ajax,Jquery,Ajax,在发送函数之前我不知道如何写 以下代码 $.post( "<?=URL?>filter-subcat.php", { service:service_arr, facility:facility_arr, product:product_arr, location:location_arr
$.post(
"<?=URL?>filter-subcat.php",
{
service:service_arr,
facility:facility_arr,
product:product_arr,
location:location_arr
},
function(data){
var result = $('<div />').append(data).find('#result').html();
$("#result1").html(result);
$("#result1").addClass('active');
$("#loader").html("");
$("#shops").html(data);
},
function(beforeSend)
{
$(".modal_1").show();
$(".fade_1").show();
},
function(complete){
$(".modal_1").hide();
$(".fade_1").hide();
});
});
$.post(
“filter subcat.php”,
{
服务:服务,
设施:设施,
产品:产品,
地点:地点
},
功能(数据){
var result=$('').append(data.find('#result').html();
$(“#result1”).html(结果);
$(“#result1”).addClass('active');
$(“#加载器”).html(“”);
$(“#shops”).html(数据);
},
功能(发送前)
{
$(“.modal_1”).show();
$(“.fade_1”).show();
},
功能(完整){
$(“.modal_1”).hide();
$(“.fade_1”).hide();
});
});
您不能将在发送之前使用$.post()
,而可以使用.ajaxStart()/.ajaxComplete()
方法,但这些方法应绑定到文档
而不是元素:
$(document).ajaxStart(function(){
$(".modal_1, .fade_1").show();
}).ajaxComplete(function(){
$(".modal_1, .fade_1").hide();
});
如果要在发送之前使用
,则必须使用$.ajax()
:
$.ajax({
url:"",
type:"",
dataType:"",
beforeSend:function(){},
success:function(){},
error:function(){},
complete:function(){}
});
您应该阅读Jquery文档:
正如您所看到的,您必须使用$.ajax()函数,实际上您的代码是这两者的混合,并且存在一些错误
$.ajax( {
method: "POST",
url: "<?=URL?>filter-subcat.php",
data: {
service:service_arr,
facility:facility_arr,
product:product_arr,
location:location_arr
},
done:function(data){
var result = $('<div />').append(data).find('#result').html();
$("#result1").addClass('active').html(result);
$("#loader").html("");
$("#shops").html(data);
},
beforeSend:function(){
$(".modal_1,.fade_1").show();
},
always:function() {
$(".modal_1,.fade_1").hide();
},
error:function(jqXHR,textStatus,errorThrown){
alert( "error" );
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}})
$.ajax({
方法:“张贴”,
url:“filter subcat.php”,
数据:{
服务:服务,
设施:设施,
产品:产品,
地点:地点
},
完成:功能(数据){
var result=$('').append(data.find('#result').html();
$(“#result1”).addClass('active').html(结果);
$(“#加载器”).html(“”);
$(“#shops”).html(数据);
},
beforeSend:function(){
$(“.modal_1,.fade_1”).show();
},
始终:函数(){
$(“.modal_1,.fade_1”).hide();
},
错误:函数(jqXHR、textStatus、errorshown){
警报(“错误”);
console.log(jqXHR);
console.log(textStatus);
console.log(错误抛出);
}})
使用以下格式
$.ajax({
beforeSend: function() {
//code to execute before sending request
}, //Show spinner
complete: function() {
// code to execute after ajax completion
},
url: url,
type: 'POST',
dataType: 'json',
headers: { //if any},
data: {},
success: function (data){
},
error : function (data){
}
});
你应该阅读Jquery文档…你也一样…去文档看看你发布了什么错误?是的,对不起,我太快了,我更新了我的帖子,谢谢!谢谢它的工作,但回应后来的加载程序没有隐藏你可以张贴给我你的html plz加载程序?顺便说一句,我对代码做了一些修改,向您展示了如何减少lines@NorlihazmeyGhazali检查添加的版本:添加的版本:3.0.Opps,您是对的。谢谢你指点。编号相当混乱。