2011-11-25 120 views

回答

16

您應該使用$.ajaxComplete();

​​

這將被觸發後,每個Ajax調用你使頁面

否則您使用ajax()並設置完整的財產

$.ajax({ 
    url: "myurl", 
    complete: function(){ 
       alert("complete"); 
      } 
    //set all the other options as usual 
1

如果您想要爲特定呼叫執行此操作,那麼complete功能可能就是您需要的功能。如果你希望這是全球性的,對於所有的阿賈克斯調用,那麼Nicola的答案應該是你需要的。

以下是針對Ajax調用的jQuery documentation

5

您可以使用任何jQuery AJAX方法的回調來延遲執行另一個函數,直到請求完成。

例子:

$.post('/some/url', somedata, function() { 
     // put the code you want to execute on completion here 
    }); 

對於更復雜的情況下,使用實際ajax方法,讓你鉤成功,完成,錯誤和其他事件。通常,你只需要成功和錯誤。

$.ajax('/some/url', { 
     data: somedata, 
     type: 'post', 
     success: function(result) { 
      // success code execution here 
     }, 
     error: function(xhr,status,error) { 
      // error code here 
     }, 
     complete: function(xhr,status) { 
      // completion code here 
     } 
    }); 
相關問題