public class XMLHttpRequest extends JavaScriptObject
RequestBuilder
class unless they
need specific functionality provided by the XMLHttpRequest object.
See http://www.w3.org/TR/XMLHttpRequest//Modifier and Type | Class and Description |
---|---|
static class |
XMLHttpRequest.ResponseType
The type of response expected from the XHR.
|
Modifier and Type | Field and 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.
|
Modifier | Constructor and Description |
---|---|
protected |
XMLHttpRequest() |
Modifier and Type | Method and 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(java.lang.String responseType)
Sets the response type.
|
void |
setResponseType(XMLHttpRequest.ResponseType responseType)
Sets the response type.
|
void |
setWithCredentials(boolean withCredentials)
Sets withCredentials attribute.
|
cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString
public static final int UNSENT
public static final int OPENED
public static final int HEADERS_RECEIVED
public static final int LOADING
public static final int DONE
public static XMLHttpRequest create()
public final void abort()
public final void clearOnReadyStateChange()
ReadyStateChangeHandler
.
See http://www.w3.org/TR/XMLHttpRequest/#handler-xhr-onreadystatechange.
clearOnReadyStateChange()
public final java.lang.String getAllResponseHeaders()
See http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders-method.
public final int getReadyState()
See http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-state.
public final ArrayBuffer getResponseArrayBuffer()
ArrayBuffer
.ArrayBuffer
containing the response, or null if the
request is in progress or failedpublic final java.lang.String getResponseHeader(java.lang.String header)
See http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader-method.
header
- the response header to be retrievedpublic final java.lang.String getResponseText()
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute.
public final java.lang.String getResponseType()
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
public final int getStatus()
See http://www.w3.org/TR/XMLHttpRequest/#the-status-attribute.
public final java.lang.String getStatusText()
See http://www.w3.org/TR/XMLHttpRequest/#the-statustext-attribute.
public final void open(java.lang.String httpMethod, java.lang.String url)
httpMethod
- the HTTP method to useurl
- the URL to be openedpublic final void open(java.lang.String httpMethod, java.lang.String url, java.lang.String user)
httpMethod
- the HTTP method to useurl
- the URL to be openeduser
- user to use in the URLpublic final void open(java.lang.String httpMethod, java.lang.String url, java.lang.String user, java.lang.String password)
httpMethod
- the HTTP method to useurl
- the URL to be openeduser
- user to use in the URLpassword
- password to use in the URLpublic final void send()
send(String)
with null
as an argument, because the
no-argument send()
method is unavailable on Firefox.public final void send(java.lang.String requestData)
requestData
- the data to be sent with the requestpublic final void setOnReadyStateChange(ReadyStateChangeHandler handler)
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.
handler
- the handler to be called when the ready state changesclearOnReadyStateChange()
public final void setRequestHeader(java.lang.String header, java.lang.String value)
See http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method.
header
- the header to be setvalue
- the header's valuepublic final void setWithCredentials(boolean withCredentials)
See http://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute.
withCredentials
- whether to include credentials in XHRpublic final void setResponseType(XMLHttpRequest.ResponseType responseType)
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
responseType
- the type of response desired. See XMLHttpRequest.ResponseType
for limitations on using the different valuespublic final void setResponseType(java.lang.String responseType)
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
responseType
- the type of response desired. See XMLHttpRequest.ResponseType
for limitations on using the different values