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.
|
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 . |
String |
getResponseHeader(String header)
Gets an HTTP response header.
|
String |
getResponseText()
Gets the response text.
|
String |
getResponseType()
Gets the response type.
|
int |
getStatus()
Gets the status code.
|
String |
getStatusText()
Gets the status text.
|
void |
open(String httpMethod,
String url)
Opens an asynchronous connection.
|
void |
open(String httpMethod,
String url,
String user)
Opens an asynchronous connection.
|
void |
open(String httpMethod,
String url,
String user,
String password)
Opens an asynchronous connection.
|
void |
send()
Initiates a request with no request data.
|
void |
send(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(String header,
String value)
Sets a request header.
|
void |
setResponseType(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 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 String getResponseHeader(String header)
See http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader-method.
header
- the response header to be retrievedpublic final String getResponseText()
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute.
public final 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 String getStatusText()
See http://www.w3.org/TR/XMLHttpRequest/#the-statustext-attribute.
public final void open(String httpMethod, String url)
httpMethod
- the HTTP method to useurl
- the URL to be openedpublic final void open(String httpMethod, String url, String user)
httpMethod
- the HTTP method to useurl
- the URL to be openeduser
- user to use in the URLpublic final void open(String httpMethod, String url, String user, 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(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(String header, 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(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 valuesCopyright © 2018. All rights reserved.