Dart API Referencedart:htmlXMLHttpRequest

XMLHttpRequest Interface

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.

Extends

EventTarget

Constructors

Code new XMLHttpRequest.get(String url, onSuccess(XMLHttpRequest request)) #

XMLHttpRequest.get(String url, onSuccess(XMLHttpRequest request));

Code new XMLHttpRequest() #

XMLHttpRequest();

Static Fields

Code final int DONE #

static final int DONE = 4;

Code final int HEADERS_RECEIVED #

static final int HEADERS_RECEIVED = 2;

Code final int LOADING #

static final int LOADING = 3;

Code final int OPENED #

static final int OPENED = 1;

Code final int UNSENT #

static final int UNSENT = 0;

Methods

Code void abort() #

Aborts the request if it has already been sent.
void abort();

Code String getAllResponseHeaders() #

string 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.

String getAllResponseHeaders();

Code String getResponseHeader(String header) #

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.
String getResponseHeader(String header);

Code XMLHttpRequestEvents get on() #

XMLHttpRequestEvents get on();

Code void open(String method, String url, [bool async, String user, String password]) #

Initializes a request. This method is to be used from JavaScript code; to initialize a request from native code, use openRequest()instead.

Note: Calling this method an already active request (one for which open()or openRequest()has already been called) is the equivalent of calling abort().
Parameters
method
The HTTP method to use; either "POST" or "GET". Ignored for non-HTTP(S) URLs.
url
The URL to which to send the request.
async
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
The optional user name to use for authentication purposes; by default, this is an empty string.
password
The optional password to use for authentication purposes; by default, this is an empty string.

void open(String method, String url, [bool async, String user, String password]);

Code void overrideMimeType(String override) #

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().
void overrideMimeType(String override);

Code void send([data]) #

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.

Note: Any event listeners you wish to set must be set before calling send().
Parameters
body
This may be an nsIDocument, nsIInputStream, or a string (an nsISupportsString 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 a FormData object.
void send([data]);

Code void setRequestHeader(String header, String value) #

Sets the value of an HTTP request header.You must call open()before using this method.

Parameters
header
The name of the header whose value is to be set.
value
The value to set as the body of the header.
void setRequestHeader(String header, String value);

Code void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) #

void $dom_addEventListener(String type, EventListener listener, [bool useCapture]);

Code bool $dom_dispatchEvent(Event evt) #

bool $dom_dispatchEvent(Event evt);

Code void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #

void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]);

Fields

Code final int readyState #

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.
final int readyState;

Code final Object response #

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.
final Object response;

Code final String responseText #

The response to the request as text, or null if the request was unsuccessful or has not yet been sent. Read-only.
final String responseText;

Code String responseType #

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
String responseType;

Code final Document responseXML #

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.

Note: If the server doesn't apply the text/xml Content-Type header, you can use overrideMimeType()to force XMLHttpRequest to parse it as XML anyway.
final Document responseXML;

Code final int status #

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.
final int status;

Code final String statusText #

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.
final String statusText;

Code final XMLHttpRequestUpload upload #

The upload process can be tracked by adding an event listener to upload. New in Firefox 3.5
final XMLHttpRequestUpload upload;

Code bool withCredentials #

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

Note: This never affects same-site requests.

The default is false.

bool withCredentials;

This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.