Description
Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts
Provides a means to interact with web servers. It is a near-complete implementation of the XMLHttpRequest API described in the Mozilla docs: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest.Create using new XMLHttpRequest(...)
.
Properties
Name | Type | Summary |
---|---|---|
response | * |
The response data. Read-only. |
responseText | string |
The response data as text. Read-only. |
responseType | string |
The response type required or received (e.g., |
status | number |
The HTTP response status
code ( |
statusText | string |
The HTTP response status text. Read-only. |
readyState | XMLHttpRequest.ReadyState |
The status of the request. Read-only. |
errorCode | XMLHttpRequest.NetworkError |
The network result of the request: including, |
timeout | number |
The time a request can take before timing out, in ms. |
UNSENT | XMLHttpRequest.ReadyState |
Request has been created; XMLHttpRequest.open not called yet. Read-only. |
OPENED | XMLHttpRequest.ReadyState |
XMLHttpRequest.open has been called. Read-only. |
HEADERS_RECEIVED | XMLHttpRequest.ReadyState |
XMLHttpRequest.send has been called; headers and status are available. Read-only. |
LOADING | XMLHttpRequest.ReadyState |
Downloading; XMLHttpRequest.responseText has partial data. Read-only. |
DONE | XMLHttpRequest.ReadyState |
Operation complete. Read-only. |
ontimeout | XMLHttpRequest~onTimeoutCallback |
Function called when the request times out. Note: This is called in addition to any function set for |
onreadystatechange | XMLHttpRequest~onReadyStateChangeCallback |
Function called when the request's ready state changes. |
Constructor |
---|
new XMLHttpRequest( )
|
Examples
var URL = "https://www.highfidelity.com/";
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
if (req.readyState === req.DONE) {
if (req.status === 200) {
print("Success");
print("Content type:", req.getResponseHeader("content-type"));
print("Content:", req.responseText.slice(0, 100), "...");
} else {
print("Error", req.status, req.statusText);
}
req = null;
}
};
req.open("GET", URL);
req.send();
var URL = "https://www.highfidelity.com/";
var req = new XMLHttpRequest();
req.requestComplete.connect(function () {
if (req.status === 200) {
print("Success");
print("Content type:", req.getResponseHeader("content-type"));
print("Content:", req.responseText.slice(0, 100), "...");
} else {
print("Error", req.status, req.statusText);
}
req = null;
});
req.open("GET", URL);
req.send();
Methods
Name | Return Value | Summary |
---|---|---|
abort
|
None |
Aborts the request. |
getAllResponseHeaders
|
string |
Gets the response headers. |
getResponseHeader
|
string |
Gets a response header. |
open
|
None |
Initializes a request. |
send
|
None |
Sends the request to the server. |
setRequestHeader
|
None |
Sets the value of an HTTP request header. Must be called after XMLHttpRequest.open but before XMLHttpRequest.send; |
Signals
Name | Summary |
---|---|
requestComplete
|
Triggered when the request is complete — with or without error (incl. timeout). |
Type Definitions
NetworkError Type: number |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The type of network error.
|
ReadyState Type: number |
||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The state of an XMLHttpRequest.
|
onReadyStateChangeCallback( )
Type: function |
---|
Called when the request's ready state changes. |
onTimeoutCallback( )
Type: function |
---|
Called when the request times out. |
Method Details
(static) abort( ) |
---|
Aborts the request. |
(static) getAllResponseHeaders( ) → {string}
Returns: The response headers, separated by "\n" characters.
|
---|
Gets the response headers. |
(static) getResponseHeader( name ) → {string}
Returns: The response header. |
||||||
---|---|---|---|---|---|---|
Gets a response header. Parameters
|
(static) open( method, url, asyncopt, usernameopt, passwordopt ) | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Initializes a request. Parameters
|
(static) send( dataopt ) | ||||||||
---|---|---|---|---|---|---|---|---|
Sends the request to the server. Parameters
|
(static) setRequestHeader( name, value ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Sets the value of an HTTP request header. Must be called after XMLHttpRequest.open but before XMLHttpRequest.send; Parameters
|
Signal Details
requestComplete(
)
Returns: Signal |
---|
Triggered when the request is complete — with or without error (incl. timeout). |