About XMLHttpRequest Object

本文详细介绍了XMLHttpRequest对象的属性和方法,包括如何设置事件处理器、获取请求状态及响应内容等,并解释了请求操作的不同状态和HTTP状态码的意义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

XMLHttpRequest 对象

属性列表
属性描述
onreadystatechangeSets or retrieves the event handler for asynchronous requests.
readyStateRetrieves the current state of the request operation.(查看)
responseBodyRetrieves the response body as an array of unsigned bytes.
responseTextRetrieves the response body as a string.
responseXMLRetrieves the response body as an XML Document Object Model (DOM) object.
statusRetrieves the HTTP status code of the request.(查看)
statusTextRetrieves the friendly HTTP status of the request.

方法列表
方法描述
abortCancels the current HTTP request.
getAllResponseHeadersReturns the complete list of response headers.
getResponseHeaderReturns the specified response header.
openAssigns method, destination URL, and other optional attributes of a pending request.
sendSends an HTTP request to the server and receives a response.
setRequestHeaderAdds custom HTTP headers to the request.

请求操作的当前状态
(0)UNINITIALIZEDThe object has been created, but not initialized (the open method has not been called).
(1) LOADINGThe object has been created, but the send method has not been called.
(2) LOADEDThe send method has been called, but the status and headers are not yet available.
(3) INTERACTIVESome data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.
(4) COMPLETEDAll the data has been received, and the complete data is available in the responseBody and responseText properties.

HTTP请求的状态码
Number Description
100Continue
101Switching protocols
200OK
201Created
202Accepted
203Non-Authoritative Information
204No Content
205Reset Content
206Partial Content
300Multiple Choices
301Moved Permanently
302Found
303See Other
304Not Modified
305Use Proxy
307Temporary Redirect
400Bad Request
401Unauthorized
402Payment Required
403Forbidden
404Not Found
405Method Not Allowed
406Not Acceptable
407Proxy Authentication Required
408Request Timeout
409Conflict
410Gone
411Length Required
412Precondition Failed
413Request Entity Too Large
414Request-URI Too Long
415Unsupported Media Type
416Requested Range Not Suitable
417Expectation Failed
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Timeout
505HTTP Version Not Supported
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值