过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

XDomainRequest is an implementation of HTTP access control (CORS) that worked in Internet Explorer 8 and 9. It was removed in Internet Explorer 10 in favor of using XMLHttpRequest with proper CORS; if you are targeting Internet Explorer 10 or later, or wish to support any other browser, you need to use standard HTTP access control .

This interface can send both GET and POST requests.

句法

var xdr = new XDomainRequest();
					

返回新的 XDomainRequest object, which can then be used to make and manage these requests.

特性

XDomainRequest.timeout

Gets or sets the amount of time until a request times out.

XDomainRequest.responseText

Gets the response body as a string.

方法

XDomainRequest.open()

Opens the request, specifing the method (GET/POST) and URL.

XDomainRequest.send()

Sends the request. POST data is specified in this method.

XDomainRequest.abort()

Aborts the request.

事件处理程序

XDomainRequest.onprogress

A handler for when the request has made progress between the send method call and the onload event.

XDomainRequest.ontimeout

A handler for when the request times out.

XDomainRequest.onerror

A handler for when a request has errored.

XDomainRequest.onload

A handler for when the full response has been received from the server.

范例

if(window.XDomainRequest){
  var xdr = new XDomainRequest();
  xdr.open("get", "http://example.com/api/method");
  xdr.onprogress = function () {
    //Progress
  };
  xdr.ontimeout = function () {
    //Timeout
  };
  xdr.onerror = function () {
    //Error Occurred
  };
  xdr.onload = function() {
    //success(xdr.responseText);
  }
  setTimeout(function () {
    xdr.send();
  }, 0);
}
					

注意: xdr.send() call is wrapped in a timeout (see window.setTimeout() to prevent an issue with the interface where some requests are lost if multiple XDomainRequest s are being sent at the same time.

注意: xdr.onprogress event should always be defined, even as an empty function, or XDomainRequest may not fire onload for duplicate requests.

安全性

The XDomainRequest is built to be secure in multiple ways.

  • The origin's security protocol must match that of the requested URL. (http to http, https to https). If these do not match, the request will error "Access is Denied".
  • The requested URL's server must have the Access-Control-Allow-Origin header set to either all ("*") or to include the origin of the request.

规范

This interface and its methods are non-standard.

浏览器兼容性

The compatibility table on 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
XDomainRequest 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
abort 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
onerror 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
onload 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
onprogress 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
ontimeout 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
open 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
responseText 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
send 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
timeout 弃用 非标 Chrome No Edge No Firefox No IE 8 — 11 Opera No Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No

图例

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

元数据

  • 最后修改: