XMLHttpRequest 方法 open() 初始化新近创建的请求,或重新初始化现有请求。

注意: 已处于活动状态的请求调用此方法 (其中 open() 已经被调用) 相当于调用 abort() .

句法

XMLHttpRequest.open(method, url[, async[, user[, password]]])
					

参数

method
HTTP 请求方法 要使用,譬如 "GET" , "POST" , "PUT" , "DELETE" ,等。忽略非 HTTP(S) URL。
url
DOMString 表示请求要发送到的 URL。
async 可选
可选布尔参数,默认为 true ,指示是否履行异步操作。若此值为 false send() 方法不返回直到收到响应。若 true ,使用事件监听器提供已完成事务的通知。这 must 为 true 若 multipart 属性为 true ,或者会抛出异常。 注意: 在主线程中的同步请求很容易破坏用户体验,且应该避免;事实上,许多浏览器已完全弃用支持主线程同步 XHR。同步请求是准许的在 Worker
user 可选
用于身份验证目的可选用户名;默认情况下,这是 null 值。
password 可选
用于身份验证目的可选口令;默认情况下,这是 null 值。

规范

规范 状态 注释
XMLHttpRequest
在该规范中的 open() 定义。
实时标准 WHATWG (Web 超文本应用程序技术工作组) 实时标准

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
open Chrome 1 Edge 12 Firefox 1
1
Starting in Firefox 30, synchronous requests on the main thread have been deprecated due to their negative impact on performance and the user experience. Therefore, the async parameter may not be false except in a Worker .
IE 5 Opera 8 Safari 1.2 WebView Android 1 Chrome Android 18 Firefox Android 4
4
Starting in Firefox 30, synchronous requests on the main thread have been deprecated due to their negative impact on performance and the user experience. Therefore, the async parameter may not be false except in a Worker .
Opera Android 10.1 Safari iOS 1 Samsung Internet Android 1.0

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: