Package com.google.gwt.xhr.client

## Class XMLHttpRequest

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

-     public class XMLHttpRequest
      extends JavaScriptObject

  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//

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `XMLHttpRequest.ResponseType` | The type of response expected from the XHR.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static 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).
    `static int` | `HEADERS_RECEIVED` | The HEADERS_RECEIVED state is the state of the object when all response headers have been received.
    `static int` | `LOADING` | The LOADING state is the state of the object when the response entity body is being received.
    `static int` | `OPENED` | The OPENED state is the state of the object when the open() method has been successfully invoked.
    `static int` | `UNSENT` | When constructed, the XMLHttpRequest object must be in the UNSENT state.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `XMLHttpRequest()` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `abort()` | Aborts the current request.
    `void` | `clearOnReadyStateChange()` | Clears the `ReadyStateChangeHandler`.
    `static XMLHttpRequest` | `create()` | Creates an XMLHttpRequest object.
    `java.lang.String` | `getAllResponseHeaders()` | Gets all the HTTP response headers, as a single string.
    `int` | `getReadyState()` | Get's the current ready-state.
    `ArrayBuffer` | `getResponseArrayBuffer()` | Get the response as an `ArrayBuffer`.
    `java.lang.String` | `getResponseHeader​(java.lang.String header)` | Gets an HTTP response header.
    `java.lang.String` | `getResponseText()` | Gets the response text.
    `java.lang.String` | `getResponseType()` | Gets the response type.
    `int` | `getStatus()` | Gets the status code.
    `java.lang.String` | `getStatusText()` | Gets the status text.
    `void` | `open​(java.lang.String httpMethod, java.lang.String url)` | Opens an asynchronous connection.
    `void` | `open​(java.lang.String httpMethod, java.lang.String url, java.lang.String user)` | Opens an asynchronous connection.
    `void` | `open​(java.lang.String httpMethod, java.lang.String url, java.lang.String user, java.lang.String password)` | Opens an asynchronous connection.
    `void` | `send()` | Initiates a request with no request data.
    `void` | `send​(java.lang.String requestData)` | Initiates a request with data.
    `void` | `setOnReadyStateChange​(ReadyStateChangeHandler handler)` | Sets the `ReadyStateChangeHandler` to be notified when the object's ready-state changes.
    `void` | `setRequestHeader​(java.lang.String header, java.lang.String value)` | Sets a request header.
    `void` | `setResponseType​(XMLHttpRequest.ResponseType responseType)` | Sets the response type.
    `void` | `setResponseType​(java.lang.String responseType)` | Sets the response type.
    `void` | `setWithCredentials​(boolean withCredentials)` | Sets withCredentials attribute.

    - ### Methods inherited from class com.google.gwt.core.client.JavaScriptObject

      `cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### UNSENT

          public static final int UNSENT

      When constructed, the XMLHttpRequest object must be in the UNSENT state.
      See Also:
        Constant Field Values

    - #### OPENED

          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().
      See Also:
        Constant Field Values

    - #### HEADERS_RECEIVED

          public static final int HEADERS_RECEIVED

      The HEADERS_RECEIVED state is the state of the object when all response headers have been received.
      See Also:
        Constant Field Values

    - #### LOADING

          public static final int LOADING

      The LOADING state is the state of the object when the response entity body is being received.
      See Also:
        Constant Field Values

    - #### DONE

          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).
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### XMLHttpRequest

          protected XMLHttpRequest()

  - ### Method Detail

    - #### create

          public static XMLHttpRequest create()

      Creates an XMLHttpRequest object.
      Returns:
        the created object

    - #### abort

          public final void abort()

      Aborts the current request.

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

    - #### clearOnReadyStateChange

          public final void clearOnReadyStateChange()

      Clears the `ReadyStateChangeHandler`.

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

      See Also:
        `clearOnReadyStateChange()`

    - #### getAllResponseHeaders

          public final java.lang.String getAllResponseHeaders()

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

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

      Returns:
        the response headers.

    - #### getReadyState

          public final int getReadyState()

      Get's the current ready-state.

      See http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-state.

      Returns:
        the ready-state constant

    - #### getResponseArrayBuffer

          public final ArrayBuffer getResponseArrayBuffer()

      Get the response as an `ArrayBuffer`.
      Returns:
        an `ArrayBuffer` containing the response, or null if the request is in progress or failed

    - #### getResponseHeader

          public final java.lang.String getResponseHeader​(java.lang.String header)

      Gets an HTTP response header.

      See http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader-method.

      Parameters:
        `header` - the response header to be retrieved
      Returns:
        the header value

    - #### getResponseText

          public final java.lang.String getResponseText()

      Gets the response text.

      See http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute.

      Returns:
        the response text

    - #### getResponseType

          public final java.lang.String getResponseType()

      Gets the response type.

      See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute

      Returns:
        the response type

    - #### getStatus

          public final int getStatus()

      Gets the status code.

      See http://www.w3.org/TR/XMLHttpRequest/#the-status-attribute.

      Returns:
        the status code

    - #### getStatusText

          public final java.lang.String getStatusText()

      Gets the status text.

      See http://www.w3.org/TR/XMLHttpRequest/#the-statustext-attribute.

      Returns:
        the status text

    - #### open

          public final void open​(java.lang.String httpMethod,
                                 java.lang.String url)

      Opens an asynchronous connection.

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

      Parameters:
        `httpMethod` - the HTTP method to use
        `url` - the URL to be opened

    - #### open

          public final void open​(java.lang.String httpMethod,
                                 java.lang.String url,
                                 java.lang.String user)

      Opens an asynchronous connection.

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

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

    - #### open

          public final void open​(java.lang.String httpMethod,
                                 java.lang.String url,
                                 java.lang.String user,
                                 java.lang.String password)

      Opens an asynchronous connection.

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

      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

    - #### send

          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.

    - #### send

          public final void send​(java.lang.String requestData)

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

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

      Parameters:
        `requestData` - the data to be sent with the request

    - #### setOnReadyStateChange

          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/#handler-xhr-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
      See Also:
        `clearOnReadyStateChange()`

    - #### setRequestHeader

          public final void setRequestHeader​(java.lang.String header,
                                             java.lang.String value)

      Sets a request header.

      See http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method.

      Parameters:
        `header` - the header to be set
        `value` - the header's value

    - #### setWithCredentials

          public final void setWithCredentials​(boolean withCredentials)

      Sets withCredentials attribute.

      See http://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute.

      Parameters:
        `withCredentials` - whether to include credentials in XHR

    - #### setResponseType

          public final void setResponseType​(XMLHttpRequest.ResponseType responseType)

      Sets the response type.

      See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute

      Parameters:
        `responseType` - the type of response desired. See `XMLHttpRequest.ResponseType` for limitations on using the different values

    - #### setResponseType

          public final void setResponseType​(java.lang.String responseType)

      Sets the response type.

      See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute

      Parameters:
        `responseType` - the type of response desired. See `XMLHttpRequest.ResponseType` for limitations on using the different values