JavaScripture
Contribute via GitHub Feedback

XMLHttpRequest : EventTarget

XMLHttpRequest is used to make an http request to a server. It can be used to download data by making a GET request (pass 'GET' as the method when calling open()) or to send data to the server by making a POST request (send 'POST' as the method when calling open()). See also fetch.

Constructors

new XMLHttpRequest() : XMLHttpRequest

Creates a new XMLHttpRequest object. Use open() to specify the url of the resource to request and send() to begin the request.

Example:

Run

Results:

 

Instance Properties

readyState : Number  

The current state of this. Will be one of UNSENT, OPENED, HEADERS_RECEIVED, LOADING, or DONE.

Example:

Run

Results:

 

response : Object  

Returns the response from the server in the type specified by responseType. Only valid after the load event fires.

Example:

Run

Results:

 

responseText : String  

Returns the response from the server as a string. Only valid after the load event fires and if responseType is set to '' (the default) or 'text'.

Example:

Run

Results:

 

responseType : String

Determines the type returned by response. Must be set to one of the following:

responseTyperesponse returns
'' (default)Same as 'text'
'text'String
'arraybuffer'ArrayBuffer
'blob'Blob
'document'Document
'json'Object

Must be set before readyState reaches LOADING.

Example:

Run

Results:

 

responseXML : Document  

status : Number  

The http status code for the request. See statusText for a description of the code.

Example:

Run

Results:

 

statusText : String  

A description of the status return code.

Example:

Run

Results:

 

timeout : Number

upload : XMLHttpRequestUpload  

Returns an XMLHttpRequestUpload object associated with this XMLHttpRequest that can be used to track the upload status of the send() call.

withCredentials : Boolean

Instance Methods

abort() : undefined

getAllResponseHeaders() : String

Returns a string containing all header value pairs from the response.

Example:

Run

Results:

 

getResponseHeader(header : String) : String

Returns the value for the specified header. Returns null if the headers do not contain a value for header.

Example:

Run

Results:

 

open(method : String, url : String, [async = true : Boolean, [user : String, [password : String]]]) : undefined

Specifies the url to read from and the http method ('GET', 'POST', 'PUT', 'DELETE', etc) to use when reading the url. If async is true, the request will be asynchronous and you should provide an onload callback to be called when the read completes. In general, it is best to use the asynchronous request so the browser remains responsive while the request is in progress. Call send() to begin the request.

Example:

Run

Results:

 

overrideMimeType(mime : String) : undefined

send 6 variants
send() : undefined

send(data : ArrayBuffer) : undefined

Sends the specified data to the server.

send(data : Blob) : undefined

Sends the specified Blob to the server.

send(data : Document) : undefined

Sends the specified document to the server.

send(data : String) : undefined

Sends the specified string to the server.

send(data : FormData) : undefined

Sends the specified FormData to the server.

Example:

Run

Results:

 

setRequestHeader(header : String, value : String) : undefined

Instance Events

onabort / 'abort'  
listener(event : ProgressEvent) : undefined

onerror / 'error'  
listener(event : ProgressEvent) : undefined

onload / 'load'  
listener(event : ProgressEvent) : undefined

onloadend / 'loadend'  
listener(event : ProgressEvent) : undefined

onloadstart / 'loadstart'  
listener(event : ProgressEvent) : undefined

onprogress / 'progress'  
listener(event : ProgressEvent) : undefined

onreadystatechange / 'readystatechange'  
listener(event : Event) : undefined

ontimeout / 'timeout'  
listener(event : ProgressEvent) : undefined

XMLHttpRequest Properties

DONE : Number    

HEADERS_RECEIVED : Number    

LOADING : Number    

OPENED : Number    

UNSENT : Number