Class XMLHttpRequest
RequestBuilder
class unless they
need specific functionality provided by the XMLHttpRequest object.
See http://www.w3.org/TR/XMLHttpRequest//-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The type of response expected from the XHR. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
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 final int
The HEADERS_RECEIVED state is the state of the object when all response headers have been received.static final int
The LOADING state is the state of the object when the response entity body is being received.static final int
The OPENED state is the state of the object when the open() method has been successfully invoked.static final int
When constructed, the XMLHttpRequest object must be in the UNSENT state. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
abort()
Aborts the current request.final void
Clears theReadyStateChangeHandler
.static XMLHttpRequest
create()
Creates an XMLHttpRequest object.final String
Gets all the HTTP response headers, as a single string.final int
Get's the current ready-state.final ArrayBuffer
Get the response as anArrayBuffer
.final String
getResponseHeader
(String header) Gets an HTTP response header.final String
Gets the response text.final String
Gets the response type.final int
Gets the status code.final String
Gets the status text.final void
Opens an asynchronous connection.final void
Opens an asynchronous connection.final void
Opens an asynchronous connection.final void
send()
Initiates a request with no request data.final void
Initiates a request with data.final void
Sets theReadyStateChangeHandler
to be notified when the object's ready-state changes.final void
setRequestHeader
(String header, String value) Sets a request header.final void
setResponseType
(XMLHttpRequest.ResponseType responseType) Sets the response type.final void
setResponseType
(String responseType) Sets the response type.final 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
-
Field Details
-
UNSENT
public static final int UNSENTWhen constructed, the XMLHttpRequest object must be in the UNSENT state.- See Also:
-
OPENED
public static final int OPENEDThe 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:
-
HEADERS_RECEIVED
public static final int HEADERS_RECEIVEDThe HEADERS_RECEIVED state is the state of the object when all response headers have been received.- See Also:
-
LOADING
public static final int LOADINGThe LOADING state is the state of the object when the response entity body is being received.- See Also:
-
DONE
public static final int DONEThe 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:
-
-
Constructor Details
-
XMLHttpRequest
protected XMLHttpRequest()
-
-
Method Details
-
create
Creates an XMLHttpRequest object.- Returns:
- the created object
-
abort
public final void abort()Aborts the current request. -
clearOnReadyStateChange
public final void clearOnReadyStateChange()Clears theReadyStateChangeHandler
.See http://www.w3.org/TR/XMLHttpRequest/#handler-xhr-onreadystatechange.
- See Also:
-
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
Get the response as anArrayBuffer
.- Returns:
- an
ArrayBuffer
containing the response, or null if the request is in progress or failed
-
getResponseHeader
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
Gets the response text.See http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute.
- Returns:
- the response text
-
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
Gets the status text.See http://www.w3.org/TR/XMLHttpRequest/#the-statustext-attribute.
- Returns:
- the status text
-
open
Opens an asynchronous connection.- Parameters:
httpMethod
- the HTTP method to useurl
- the URL to be opened
-
open
Opens an asynchronous connection.- Parameters:
httpMethod
- the HTTP method to useurl
- the URL to be openeduser
- user to use in the URL
-
open
Opens an asynchronous connection.- Parameters:
httpMethod
- the HTTP method to useurl
- the URL to be openeduser
- user to use in the URLpassword
- password to use in the URL
-
send
public final void send()Initiates a request with no request data. This simply callssend(String)
withnull
as an argument, because the no-argumentsend()
method is unavailable on Firefox. -
send
Initiates a request with data. If there is no data, specify null.- Parameters:
requestData
- the data to be sent with the request
-
setOnReadyStateChange
Sets theReadyStateChangeHandler
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:
-
setRequestHeader
Sets a request header.See http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method.
- Parameters:
header
- the header to be setvalue
- 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
Sets the response type.See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
- Parameters:
responseType
- the type of response desired. SeeXMLHttpRequest.ResponseType
for limitations on using the different values
-
setResponseType
Sets the response type.See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
- Parameters:
responseType
- the type of response desired. SeeXMLHttpRequest.ResponseType
for limitations on using the different values
-