XMLHttpRequest.statusText - Web APIs 编辑
The read-only XMLHttpRequest.statusText
property returns a DOMString
containing the response's status message as returned by the HTTP server. Unlike XMLHTTPRequest.status
which indicates a numerical status code, this property contains the text of the response status, such as "OK" or "Not Found". If the request's readyState
is in UNSENT
or OPENED
state, the value of statusText
will be an empty string.
If the server response doesn't explicitly specify a status text, statusText
will assume the default value "OK".
Responses over an HTTP/2 connection will always have a empty string as status message as HTTP/2 does not support them.
Example
var xhr = new XMLHttpRequest();
console.log('0 UNSENT', xhr.statusText);
xhr.open('GET', '/server', true);
console.log('1 OPENED', xhr.statusText);
xhr.onprogress = function () {
console.log('3 LOADING', xhr.statusText);
};
xhr.onload = function () {
console.log('4 DONE', xhr.statusText);
};
xhr.send(null);
/**
* Outputs the following:
*
* 0 UNSENT
* 1 OPENED
* 3 LOADING OK
* 4 DONE OK
*/
Specifications
Specification | Status | Comment |
---|---|---|
XMLHttpRequest | Living Standard | WHATWG living standard |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论