XMLHttpRequest.timeout property is an unsigned long representing the number of milliseconds a request can take before automatically being terminated. The default value is 0, which means there is no timeout. Timeout shouldn't be used for synchronous XMLHttpRequests requests used in a document environment or it will throw an InvalidAccessError exception. When a timeout happens, a timeout event is fired.

注意: You may not use a timeout for synchronous requests with an owning window.
Using a timeout with an asynchronous request

In Internet Explorer, the timeout property may be set only after calling the open() method and before calling the send() 方法。

范例

var xhr = new XMLHttpRequest();
xhr.open('GET', '/server', true);
xhr.timeout = 2000; // time in milliseconds
xhr.onload = function () {
  // Request finished. Do processing here.
};
xhr.ontimeout = function (e) {
  // XMLHttpRequest timed out. Do something here.
};
xhr.send(null);
					

规范

规范 状态 注释
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
timeout Chrome 29 Edge 12 Firefox 12 IE 8 Opera 17
17
不支持 12 — 16
Safari 6.1 WebView Android ≤37 Chrome Android 29 Firefox Android 14 Opera Android 18
18
不支持 12 — 16
Safari iOS 7 Samsung Internet Android 2.0

图例

完整支持

完整支持

元数据

  • 最后修改: