加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax xmlHttp.status

发布时间:2020-12-16 00:43:12 所属栏目:百科 来源:网络整理
导读:原网址:http://blog.sina.com.cn/s/blog_5c4a1a800100h80w.html Ajax中,XMLHttpRequest对象的status属性一般用来返回服务器的HTTP状态码。status为200表示“成功”,status为404代表“页面未找到”。很多书上都是这样写的,一点也不错。 但是,有时候,特

原网址:http://blog.sina.com.cn/s/blog_5c4a1a800100h80w.html

Ajax中,XMLHttpRequest对象的status属性一般用来返回服务器的HTTP状态码。status为200表示“成功”,status为404代表“页面未找到”。很多书上都是这样写的,一点也不错。   但是,有时候,特别是刚开始学Ajax的时候,可能会将代码直接在本地运行。这样就出现问题了。如果在本地运行(如:C:ajaxhelloworld.htm),那么status属性不管是在“成功”还是“页面未找到”的情况下,都返回的是0,而不是200和404。这个时候如果还用if(xmlHttp.status==200)来判断运行,则会毫无结果。如果要在本地测试,最好写成if(xmlHttp.status==200 || xmlHttp.status==0)的形式来判断。   就像我前面所说的,这并不是说很多书或文章里写错了。因为这些文章里都写的是从服务器返回状态,而并没有说从本地返回的情况,应该算是漏掉了吧。 下面把STATUS各个值所代表的状态列出来: XMLHTTP中 xmlHttp.status=0 xmlHttp.status=200 xmlHttp.status=500 等等; 对应的HTTP的状态,见下表: status状态值 长整形标准http状态码,定义如下: Number Description 100 Continue 101 Switching protocols 200 OK 201 Created 202 Accepted 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 300 Multiple Choices 301 Moved Permanently 302 Found 303 See Other 304 Not Modified 305 Use Proxy 307 Temporary Redirect 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Request Entity Too Large 414 Request-URI Too Long 415 Unsupported Media Type 416 Requested Range Not Suitable 417 Expectation Failed 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读