2011-05-08 26 views
0

我經常在ajax函數function(event, data, status, xhr)中看到這個。我想知道這些參數是指什麼以及如何使用它們。ajax函數中的參數是指什麼?

+0

檢查出[文檔](http://api.jquery.com/jQuery.ajax/)給每個事件或功能,它通常相對很好地解釋 – 2011-05-08 16:18:32

回答

2
  • data:由服務器返回的數據(可以是HTML,XML,JSON,...)
  • status:字符串分類請求( 「成功」 的狀態, 「notmodified」,「錯誤」,‘超時’,‘中止’或‘parsererror’)
  • xhr:用來發送Ajax請求

在所有你關心的情況下,99.99%的jqXHR object是通過返回的data服務器。您可能也有興趣Ajax請求是成功還是失敗:

$.ajax({ 
    url: '/somescript.cgi', 
    success: function(data) { 
     // The request succeeded => do something with the data returned by the server 
    }, 
    error: function() { 
     // The request failed 
    } 
}); 
相關問題