ajax 在请求时一共有0-4五种状态,
Holds the status of the XMLHttpRequest. Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
用原生javascript处理ajax:
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}jquery用suceess, error, complete, beforesend等方法对应xhr的状态,但却没有对应readystate等于3时的函数,
在stackoverflow看到一解决办法,不知可行否
var xhr = $.ajax({ ... });
xhr.onreadystatechange = function() { alert(xhr.readyState); };
本文介绍了AJAX请求的五个状态:未初始化、建立连接、接收请求、处理请求及完成响应。并提供了使用原生JavaScript和jQuery处理这些状态的方法。
1万+

被折叠的 条评论
为什么被折叠?



