XMLHttpRequest
方法
send()
sends the request to the server.
If the request is asynchronous (which is the default), this method returns as soon as the request is sent and the result is delivered using events. If the request is synchronous, this method doesn't return until the response has arrived.
send()
accepts an optional parameter which lets you specify the request's body; this is primarily used for requests such as
PUT
. If the request method is
GET
or
HEAD
,
body
parameter is ignored and the request body is set to
null
.
若无
Accept
header has been set using the
setRequestHeader()
,
Accept
header with the type
"*/*"
(any type) is sent.
XMLHttpRequest.send(body)
body
可选
Document
, in which case it is serialized before being sent.
XMLHttpRequestBodyInit
, which
per the Fetch spec
可以是
Blob
,
BufferSource
,
FormData
,
URLSearchParams
,或
USVString
对象。
null
null
被使用。
The best way to send binary content (e.g. in file uploads) is by using an
ArrayBufferView
or
Blob
in conjunction with the
send()
方法。
undefined
.
| 异常 | 描述 |
|---|---|
InvalidStateError
|
send()
has already been invoked for the request, and/or the request is complete.
|
NetworkError
|
The resource type to be fetched is a Blob, and the method is not
GET
.
|
var xhr = new XMLHttpRequest(); xhr.open('GET', '/server', true); xhr.onload = function () { // Request finished. Do processing here. }; xhr.send(null); // xhr.send('string');//xhr.send(new Blob()); // xhr.send(new Int8Array()); // xhr.send(document);
var xhr = new XMLHttpRequest();
xhr.open("POST", '/server', true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() { // Call a function when the state changes.
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
// Request finished. Do processing here.
}
}
xhr.send("foo=bar&lorem=ipsum");
// xhr.send(new Int8Array());
// xhr.send(document);
| 规范 | 状态 | 注释 |
|---|---|---|
|
XMLHttpRequest
The definition of 'send()' in that specification. |
实时标准 | WHATWG (Web 超文本应用程序技术工作组) 实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
send
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5 | 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 |
| ArrayBuffer as parameter to send() | Chrome 9 | Edge 12 | Firefox 9 | IE 10 | Opera 11.6 | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 9 | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
| ArrayBufferView as parameter to send() | Chrome 22 | Edge ≤79 | Firefox 20 | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android 20 | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
| Blob as parameter to send() | Chrome 22 | Edge 12 | Firefox 2 | IE 10 | Opera 12 | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
| FormData as parameter to send() | Chrome 6 | Edge 12 | Firefox 2 | IE 10 | Opera 12 | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
| URLSearchParams as parameter to send() | Chrome 59 | Edge ≤79 | Firefox 44 | IE ? | Opera 12 | Safari ? | WebView Android Yes | Chrome Android 59 | Firefox Android 44 | Opera Android Yes | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
兼容性未知
XMLHttpRequest