本文介绍了readyState的VS状态== 200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

xmlhttp.onreadystatechange = function()
{
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
        document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
    }
}

以上code是: HTTP://www.w3schools。 COM / AJAX / ajax_xmlhtt prequest_onreadystatechange.asp

问:

据本教程:

readyState: 4: request finished and response is ready

status: 200: "OK"

When readyState is 4 and status is 200, the response is ready:

自当 xmlhttp.readyState == 4 ,响应准备好了,为什么我们仍然需要 xmlhttp.status == 200 ?什么是xmlhttp.status == 200之间的 xmlhttp.readyState == 4 的区别

since when xmlhttp.readyState == 4, response is ready, why do we still need xmlhttp.status == 200? what is the difference between xmlhttp.readyState == 4 and xmlhttp.status == 200?

推荐答案

该响应的状态, xhr.status ,(通常)用于判断是否请求是成功还是失败。 xhr.readyState 只是用来确定请求的状态,如尚未发送(0),完全和响应收到的(4)等等。

The status of the response, xhr.status, is (generally) used to determine whether the request was successful or not. xhr.readyState is simply used to determine the state of the request, such as "has not yet been sent" (0), "complete and response received" (4), etc.

该服务器负责提供状态,而用户代理提供了的readyState

The server is responsible for providing the status, while the user agent provides the readyState.

这篇关于readyState的VS状态== 200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:13