public class

XMLHttpRequest

extends JavaScriptObject
java.lang.Object
   ↳ com.google.gwt.core.client.JavaScriptObject
     ↳ com.google.gwt.xhr.client.XMLHttpRequest

Class Overview

The native XMLHttpRequest object. Most applications should use the higher- level RequestBuilder class unless they need specific functionality provided by the XMLHttpRequest object. See http://www.w3.org/TR/XMLHttpRequest//

Summary

Constants
int DONE The DONE state is the state of the object when either the data transfer has been completed or something went wrong during the transfer (infinite redirects for instance).
int HEADERS_RECEIVED The HEADERS_RECEIVED state is the state of the object when all response headers have been received.
int LOADING The LOADING state is the state of the object when the response entity body is being received.
int OPENED The OPENED state is the state of the object when the open() method has been successfully invoked.
int UNSENT When constructed, the XMLHttpRequest object must be in the UNSENT state.
Protected Constructors
XMLHttpRequest()
Public Methods
final void abort()
Aborts the current request.
final void clearOnReadyStateChange()
static XMLHttpRequest create()
Creates an XMLHttpRequest object.
final String getAllResponseHeaders()
Gets all the HTTP response headers, as a single string.
final int getReadyState()
Get's the current ready-state.
final String getResponseHeader(String header)
Gets an HTTP response header.
final String getResponseText()
Gets the response text.
final int getStatus()
Gets the status code.
final String getStatusText()
Gets the status text.
final void open(String httpMethod, String url, String user, String password)
Opens an asynchronous connection.
final void open(String httpMethod, String url, String user)
Opens an asynchronous connection.
final void open(String httpMethod, String url)
Opens an asynchronous connection.
final void send()
Initiates a request with no request data.
final void send(String requestData)
Initiates a request with data.
final void setOnReadyStateChange(ReadyStateChangeHandler handler)
Sets the ReadyStateChangeHandler to be notified when the object's ready-state changes.
final void setRequestHeader(String header, String value)
Sets a request header.
[Expand]
Inherited Methods
From class com.google.gwt.core.client.JavaScriptObject
From class java.lang.Object

Constants

public static final int DONE

The DONE state is the state of the object when either the data transfer has been completed or something went wrong during the transfer (infinite redirects for instance).

Constant Value: 4 (0x00000004)

public static final int HEADERS_RECEIVED

The HEADERS_RECEIVED state is the state of the object when all response headers have been received.

Constant Value: 2 (0x00000002)

public static final int LOADING

The LOADING state is the state of the object when the response entity body is being received.

Constant Value: 3 (0x00000003)

public static final int OPENED

The OPENED state is the state of the object when the open() method has been successfully invoked. During this state request headers can be set using setRequestHeader() and the request can be made using send().

Constant Value: 1 (0x00000001)

public static final int UNSENT

When constructed, the XMLHttpRequest object must be in the UNSENT state.

Constant Value: 0 (0x00000000)

Protected Constructors

protected XMLHttpRequest ()

Public Methods

public final void abort ()

Aborts the current request.

See http://www.w3.org/TR/XMLHttpRequest/#abort.

public final void clearOnReadyStateChange ()

public static XMLHttpRequest create ()

Creates an XMLHttpRequest object.

Returns
  • the created object

public final String getAllResponseHeaders ()

Gets all the HTTP response headers, as a single string.

See http://www.w3.org/TR/XMLHttpRequest/#getallresponseheaders.

Returns
  • the response headers.

public final int getReadyState ()

Get's the current ready-state.

See http://www.w3.org/TR/XMLHttpRequest/#readystate.

Returns
  • the ready-state constant

public final String getResponseHeader (String header)

Parameters
header the response header to be retrieved
Returns
  • the header value

public final String getResponseText ()

Returns
  • the response text

public final int getStatus ()

Returns
  • the status code

public final String getStatusText ()

Returns
  • the status text

public final void open (String httpMethod, String url, String user, String password)

Opens an asynchronous connection.

See http://www.w3.org/TR/XMLHttpRequest/#open.

Parameters
httpMethod the HTTP method to use
url the URL to be opened
user user to use in the URL
password password to use in the URL

public final void open (String httpMethod, String url, String user)

Opens an asynchronous connection.

See http://www.w3.org/TR/XMLHttpRequest/#open.

Parameters
httpMethod the HTTP method to use
url the URL to be opened
user user to use in the URL

public final void open (String httpMethod, String url)

Opens an asynchronous connection.

See http://www.w3.org/TR/XMLHttpRequest/#open.

Parameters
httpMethod the HTTP method to use
url the URL to be opened

public final void send ()

Initiates a request with no request data. This simply calls send(String) with null as an argument, because the no-argument send() method is unavailable on Firefox.

public final void send (String requestData)

Initiates a request with data. If there is no data, specify null.

See http://www.w3.org/TR/XMLHttpRequest/#send.

Parameters
requestData the data to be sent with the request

public final void setOnReadyStateChange (ReadyStateChangeHandler handler)

Sets the ReadyStateChangeHandler to be notified when the object's ready-state changes.

See http://www.w3.org/TR/XMLHttpRequest/#onreadystatechange.

Note: Applications must call clearOnReadyStateChange() when they no longer need this object, to ensure that it is cleaned up properly. Failure to do so will result in memory leaks on some browsers.

Parameters
handler the handler to be called when the ready state changes

public final void setRequestHeader (String header, String value)

Parameters
header the header to be set
value the header's value