class js.html.XMLHttpRequest extends EventTarget
Available on js
XMLHttpRequest
is a JavaScript object that was designed by Microsoft and adopted by Mozilla, Apple, and Google. It's now being standardized in the W3C. It provides an easy way to retrieve data at a URL. Despite its name, XMLHttpRequest
can be used to retrieve any type of data, not just XML, and it supports protocols other than HTTP (including file
and ftp
).
To create an instance of XMLHttpRequest
, simply do this:
var req = new XMLHttpRequest();
For details about how to use XMLHttpRequest
, see Using XMLHttpRequest.
Documentation for this class was provided by MDN.
Class Fields
Instance Fields
var readyState:Int
The state of the request:
Value | State | Description |
0 | UNSENT | open() has not been called yet. |
1 | OPENED | send() has not been called yet. |
2 | HEADERS_RECEIVED | send() has been called, and headers and status are available. |
3 | LOADING | Downloading; responseText holds partial data. |
4 | DONE | The operation is complete. |
The response entity body according to responseType
, as an ArrayBuffer
, Blob
, Document
, JavaScript object (for "moz-json"), or string. This is NULL
if the request is not complete or was not successful. Getter throws DOMException.
var responseText:String
The response to the request as text, or null
if the request was unsuccessful or has not yet been sent. Read-only. Getter throws DOMException.
var responseType:String
Can be set to change the response type. This tells the server what format you want the response to be in.
Value | Data type of response property |
empty string | String (this is the default) |
"arraybuffer" | ArrayBuffer |
"blob" | Blob
|
"document" | Document
|
"text" | String |
"moz-json" | JavaScript object, parsed from a JSON string returned by the server Requires Gecko 9.0 |
var responseXML:Document
The response to the request as a DOM Document
object, or null
if the request was unsuccessful, has not yet been sent, or cannot be parsed as XML. The response is parsed as if it were a text/xml
stream. Read-only.
text/xml
Content-Type header, you can use overrideMimeType()
to force XMLHttpRequest
to parse it as XML anyway.The status of the response to the request. This is the HTTP result code (for example, status
is 200 for a successful request). Read-only. Getter throws DOMException.
var statusText:String
The response string returned by the HTTP server. Unlike status
, this includes the entire text of the response message ("200 OK
", for example). Read-only. Getter throws DOMException.
var upload:XMLHttpRequestUpload
The upload process can be tracked by adding an event listener to upload
.
New in Firefox 3.5
var withCredentials:Bool
Indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies or authorization headers. New in Firefox 3.5
The default is false
.
function send(data:DOMFormData):Void
function send(data:ArrayBuffer):Void
function send(data:ArrayBufferView):Void
function send(data:Document):Void
function send(data:String):Void
Sends the request. If the request is asynchronous (which is the default), this method returns as soon as the request is sent. If the request is synchronous, this method doesn't return until the response has arrived.
send()
.Parameters
body
- This may be an
nsIDocument
,nsIInputStream
, or a string (annsISupportsString
if called from native code) that is used to populate the body of a POST request. Starting with Gecko 1.9.2, you may also specify an DOMFile
, and starting with Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) you may also specify aFormData
object.