Class: XMLHttpRequest

XMLHttpRequest()

XMLHttpRequest is a JavaScript object that provides an easy way to retrieve data from a URL without having to do a full page refresh. A Web page can update just a part of the page without disrupting what the user is doing. XMLHttpRequest is used heavily in AJAX programming.

Constructor

new XMLHttpRequest()

Properties:
Name Type Description
onreadystatechange string A JavaScript function object that is called whenever the readyState attribute changes. The callback is called from the user interface thread.
readyState number The state of the request. Possible values are: 0 - when open() method has not been called yet 1 - when send() methos has not been called yet 2 - when send() method has been called, and headers and status are available 3 - downloading; responseText holds partial data 4 - operation is complete
response string The response entity body according to responseType, as an ArrayBuffer, Blob, Document, JavaScript object (for "json"), or string. This is null if the request is not complete or was not successful.
responseText string The response to the request as text, or null if the request was unsuccessful or has not yet been sent.
responseType string Can be set to change the response type. Possible values are: "" (empty string) - String (this is the default) "document" - Document "json" - JavaScript object, parsed from a JSON string returned by the server "text" - String "blob" - JavaScript object, parsed from readable stream of binary data responded by the server
responseXML string 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 or HTML. The response is parsed as if it were a text/xml stream. When the responseType is set to "document" and the request has been made asynchronously, the response is parsed as a text/html stream.
status number The status of the response to the request. This is the HTTP result code (for example, status is 200 for a successful request).
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).
timeout string The number of milliseconds a request can take before automatically being terminated. A value of 0 (which is the default) means there is no timeout.
ontimeout string A JavaScript function object that is called whenever the request times out.
upload string The upload process can be tracked by adding an event listener to upload.
withCredentials string Indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies or authorization headers. The default is false.
Deprecated:
  • since version 9.0, where XMLHttpRequest is secured within cordova-plugin-bbd-base. It will be removed in future versions.
Source:

Methods

abort()

Aborts the request if it has already been sent.
Source:

getAllResponseHeaders()

Returns all the response headers as a string, or null if no response has been received. Note: For multipart requests, this returns the headers from the current part of the request, not from the original channel.
Source:

getResponseHeader()

Returns the string containing the text of the specified header, or null if either the response has not yet been received or the header doesn't exist in the response.
Source:

open(method, url, async, user, password)

Initializes a request. This method is to be used from JavaScript code; to initialize a request from native code.
Parameters:
Name Type Description
method string The HTTP method to use, such as "GET", "POST", "PUT", "DELETE".
url string The URL to send the request to.
async boolean An optional boolean parameter, defaulting to true, indicating whether or not to perform the operation asynchronously. If this value is false, the send() method does not return until the response is received. If true, notification of a completed transaction is provided using event listeners. This must be true if the multipart attribute is true, or an exception will be thrown.
user string The optional user name to use for authentication purposes; by default, this is an empty string.
password string The optional password to use for authentication purposes; by default, this is an empty string.
Source:

overrideMimeType()

Overrides the MIME type returned by the server. This may be used, for example, to force a stream to be treated and parsed as text/xml, even if the server does not report it as such. This method must be called before send().
Source:

send()

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. It takes optional parameter data. Optional parameter data can contain following types of data: ArrayBuffer Document DOMString FormData - object with key/value pairs that can be passed to send method as parameter. User can append file from GDFileSystem by passing valid fullPath to this file as key/value
Source:

setRequestHeader()

Sets the value of an HTTP request header. You must call setRequestHeader() after open(), but before send(). If this method is called several times with the same header, the values are merged into one single request header.
Source: