只读 XMLHttpRequest.status property returns the numerical HTTP status code XMLHttpRequest 's response.

Before the request completes, the value of status is 0. Browsers also report a status of 0 in case of XMLHttpRequest 错误。

范例

var xhr = new XMLHttpRequest();
console.log('UNSENT: ', xhr.status);
xhr.open('GET', '/server');
console.log('OPENED: ', xhr.status);
xhr.onprogress = function () {
  console.log('LOADING: ', xhr.status);
};
xhr.onload = function () {
  console.log('DONE: ', xhr.status);
};
xhr.send();
/**
 * Outputs the following:
 *
 * UNSENT: 0
 * OPENED: 0
 * LOADING: 200
 * DONE: 200
 */
					

规范

规范 状态 注释
XMLHttpRequest 实时标准 WHATWG (Web 超文本应用程序技术工作组) 实时标准

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
status Chrome 1 Edge 12 Firefox 1 IE 7
7
Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject()
Opera 8 Safari 1.2 WebView Android 1 Chrome Android 18 Firefox Android 4 Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: