2009-05-29 126 views
1

確定AJAX調用成功的正確方法是什麼?確定AJAX調用成功的正確方法是什麼?

我看到的prototype.js

return !status || (status >= 200 && status < 300); 

和jQuery中:

// IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 
    return !xhr.status && location.protocol == "file:" || 
     (xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || xhr.status == 1223; 

哪一個是正確的?如果我們不使用任何Javascript庫,而是使用基本Javascript編寫AJAX,我們應該使用哪一個?

回答

5

原型似乎更「正確」,因爲它只將有效的HTTP成功代碼視爲成功。 jQuery更強大,因爲它考慮到錯誤和其他常常成功的代碼。

+1

/借調 - 我不會認爲304成功,例如,應該導致另一個行爲循環的行爲,才能建立整體成功 – annakata 2009-05-29 11:11:23

+0

他們都很好地建立了一個JavaScript庫......但在看法上有所不同它是成功的 – 2009-05-29 17:51:32

相關問題