2015-10-05 30 views
-1

發送功能我不知道如何發送前的功能 下面的代碼阿賈克斯帖子之前沒有工作

$.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(); 
      }); 

    }); 

回答

0

你不能$.post()使用beforeSend寫的,而是可以使用.ajaxStart()/.ajaxComplete()方法,但這些都應該被綁定到document沒有的元素:

$(document).ajaxStart(function(){ 
    $(".modal_1, .fade_1").show(); 
}).ajaxComplete(function(){ 
    $(".modal_1, .fade_1").hide(); 
}); 

如果你想使用beforeSend,那麼你必須使用$.ajax()

$.ajax({ 
    url:"", 
    type:"", 
    dataType:"", 
    beforeSend:function(){}, 
    success:function(){}, 
    error:function(){}, 
    complete:function(){} 
}); 
+0

這是怎麼回事? http://api.jquery.com/jquery.post/#jQuery-post-settings –

+0

感謝您的回覆 –

+0

@NorlihazmeyGhazali檢查版本添加:**版本添加:3.0 **。 – Jai

0

你應該閱讀jQuery的文檔:

http://api.jquery.com/jquery.post/

http://api.jquery.com/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); 
}}) 
+1

_您應該閱讀Jquery文檔_....同樣適用於您....轉到文檔並查看您發佈了哪些錯誤? – Jai

+0

很抱歉,我速度太快了,我更新了我的帖子,謝謝! – Froggiz

+0

感謝它的工作,但 後響應來裝載機不隱藏 –

0

使用以下格式

$.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){ 
        } 
       });