readyState的VS状态== 200

编程入门 行业动态 更新时间:2024-10-07 10:15:43
本文介绍了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

本文发布于:2023-10-10 18:23:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479367.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   readyState

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!