@JsType(isNative=true,
namespace="<global>")
public class XMLHttpRequest
extends Object
org.gwtproject.http.client.RequestBuilder class unless they need specific functionality provided
by the XMLHttpRequest object.
| Modifier and Type | Class and Description |
|---|---|
static interface |
XMLHttpRequest.Function
A callback function to map the Javascript function
|
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.
|
XMLHttpRequest.Function |
onreadystatechange
the onreadystatechange function of the request
|
static int |
OPENED
The OPENED state is the state of the object when the open() method has been successfully
invoked.
|
Object |
response
the response object contains the body of the response
|
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.
|
org.gwtproject.typedarrays.shared.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,
boolean async)
Opens an asynchronous or a synchronous connection.
|
void |
open(String httpMethod,
String url,
boolean async,
String user)
Opens an asynchronous or a synchronous connection.
|
void |
open(String httpMethod,
String url,
boolean async,
String user,
String password)
Opens an asynchronous or a synchronous 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.
|
@JsOverlay public static int UNSENT
@JsOverlay public static int OPENED
@JsOverlay public static int HEADERS_RECEIVED
@JsOverlay public static int LOADING
@JsOverlay public static int DONE
public XMLHttpRequest.Function onreadystatechange
public Object response
@JsOverlay public static XMLHttpRequest create()
public void abort()
@JsOverlay 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.
@JsProperty(name="readyState") public final int getReadyState()
See http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-state.
@JsOverlay public final org.gwtproject.typedarrays.shared.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 retrieved@JsProperty(name="responseText") public final String getResponseText()
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetext-attribute.
@JsProperty(name="responseType") public final String getResponseType()
See http://www.w3.org/TR/XMLHttpRequest/#the-responsetype-attribute
@JsOverlay public 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 values@JsProperty(name="responseType") public 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 values@JsProperty(name="status") public final int getStatus()
See http://www.w3.org/TR/XMLHttpRequest/#the-status-attribute.
@JsProperty(name="statusText") public final String getStatusText()
See http://www.w3.org/TR/XMLHttpRequest/#the-statustext-attribute.
@JsOverlay public final void open(String httpMethod, String url)
httpMethod - the HTTP method to useurl - the URL to be opened@JsOverlay public 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 URL@JsOverlay public 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 open(String httpMethod, String url, boolean async)
httpMethod - the HTTP method to useurl - the URL to be openedasync - connection is asynchronous when true, otherwise connection is synchronouspublic final void open(String httpMethod, String url, boolean async, String user)
httpMethod - the HTTP method to useurl - the URL to be openedasync - connection is asynchronous when true, otherwise connection is synchronoususer - user to use in the URLpublic final void open(String httpMethod, String url, boolean async, String user, String password)
httpMethod - the HTTP method to useurl - the URL to be openedasync - connection is asynchronous when true, otherwise connection is synchronoususer - user to use in the URLpassword - password to use in the URL@JsOverlay public 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 request@JsOverlay public 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 value@JsProperty(name="withCredentials") public final void setWithCredentials(boolean withCredentials)
See http://www.w3.org/TR/XMLHttpRequest/#the-withcredentials-attribute.
withCredentials - whether to include credentials in XHRCopyright © 2019–2020 The GWT Authors. All rights reserved.