We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick GameRuntime Quick GameNetworkNetwork Request

Network Request

Creating a Network Request Object

var xmlHttp = new XMLHttpRequest();

The XMLHttpRequest object provides full access to HTTP, allowing you to send POST and HEAD requests, as well as standard GET requests. The XMLHttpRequest object can synchronously or asynchronously return a response from the web server in the form of text or a DOM document.

Definition

Expand

API

Description

XMLHttpRequest.onreadystatechange = callBack

Specifies the response processing function.

XMLHttpRequest.open(method, url, async, username, password)

Initializes HTTP request parameters.

XMLHttpRequest.setRequestHeader(name, value)

Sets the request header.

XMLHttpRequest.send(body)

Sends an HTTP request using the parameters passed to the open() method and an optional request body passed to the send method.

XMLHttpRequest.getAllResponseHeader()

Returns all response headers.

XMLHttpRequest.getResponseHeader(header)

Returns the value of the specified HTTP response header.

XMLHttpRequest.abort()

Cancels the current request.

XMLHttpRequest.responseText

Returns the response body (excluding the headers) received by the server so far, or an empty string if no data has been received.

XMLHttpRequest.responseXML

Returns a Document object containing the XML retrieved by the request.

XMLHttpRequest.status

Parses the response into XML and returns the result as a Document object.

XMLHttpRequest.statusText

Returns the HTTP status code of a request.

XMLHttpRequest.readyState

Describes the status of an HTTP request.

XMLHttpRequest.response

Returns an ArrayBuffer, Blob, Document, or DOMString, depending on the value of XMLHttpRequest.responseType.

XMLHttpRequest.responseType

Defines enumerated values of the response type.

XMLHttpRequest.responseURL

Returns a serialized response URL. If the URL is empty, an empty string is returned.

XMLHttpRequest.timeout

Returns an unsigned long integer representing the maximum time, in milliseconds, that the request is allowed to take. If this time is exceeded, the request is automatically terminated.

XMLHttpRequest.withCredentials

Returns a boolean value, indicating whether the cross-domain Access-Control request should contain authorization information, such as cookies or authorization headers.

XMLHttpRequest.overrideMimeType

Overrides the MIME type returned by the server.

XMLHttpRequest.onreadystatechange = callBack

  • Description

    Specifies the response processing function.

XMLHttpRequest.open(method, url, async, username, password)

  • Description

    Initializes HTTP request parameters.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    method

    string

    Yes

    HTTP request method.

    url

    string

    Yes

    Request body.

    async

    boolean

    No

    Indicates whether the request should be executed asynchronously. The default value is true.

    username

    string

    No

    User name for accessing the specified URL.

    password

    string

    No

    Password for accessing the specified URL.

  • Sample code
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. var xhr = new XMLHttpRequest();
    2. xhr.open('GET', '" + "test.php"+ "', true);

XMLHttpRequest.setRequestHeader(name, value)

  • Description

    Sets the request header.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    name

    string

    Yes

    Name of the header to be set.

    value

    string

    Yes

    Header value.

  • Sample code
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. var xhr = new XMLHttpRequest();
    2. xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

XMLHttpRequest.send(body)

  • Description

    Sends an HTTP request using the parameters passed to the open() method and an optional request body passed to the send method.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    body

    string/document

    No

    String or document.

  • Sample code
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. var xhr = new XMLHttpRequest();
    2. xhr.open('POST', '" + "test.php"+ "', true);
    3. xhr.send("foo=bar&lorem=ipsum");

XMLHttpRequest.getAllResponseHeader()

  • Description

    Returns all response headers.

XMLHttpRequest.getResponseHeader(header)

  • Description

    Returns the value of the specified HTTP response header.

  • Parameters
    Expand

    Parameter

    Type

    Mandatory

    Description

    header

    string

    Yes

    Name of the HTTP response header to be returned.

  • Sample code
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. var client = new XMLHttpRequest();
    2. client.open("GET", "unicorns-are-teh-awesome.txt", true);
    3. client.send();
    4. client.onreadystatechange = function() {
    5. if(this.readyState == this.HEADERS_RECEIVED) {
    6. console.log(client.getResponseHeader("Content-Type"));
    7. }
    8. }

XMLHttpRequest.abort()

  • Description

    Cancels the current request.

XMLHttpRequest.responseText

  • Description

    Returns the response body (excluding the headers) received by the server so far, or an empty string if no data has been received.

XMLHttpRequest.responseXML

  • Description

    Returns a Document object containing the XML retrieved by the request.

XMLHttpRequest.status

  • Description

    Parses the response into XML and returns the result as a Document object.

XMLHttpRequest.statusText

  • Description

    Returns the HTTP status code of a request.

XMLHttpRequest.readyState

  • Description

    Describes the status of an HTTP request. It starts at 0 when the XMLHttpRequest object is created for the first time and progresses, reaching 4 once the full HTTP response has been received.

XMLHttpRequest.response

  • Description

    Returns an ArrayBuffer, Blob, Document, or DOMString, depending on the value of XMLHttpRequest.responseType. The return value contains the entire response entity body.

XMLHttpRequest.responseType

  • Description

    Defines enumerated values of the response type.

XMLHttpRequest.responseURL

  • Description

    Returns a serialized response URL. If the URL is empty, an empty string is returned.

XMLHttpRequest.timeout

  • Description

    Returns an unsigned long integer representing the maximum time, in milliseconds, that the request is allowed to take. If this time is exceeded, the request is automatically terminated.

XMLHttpRequest.withCredentials

  • Description

    Returns a boolean value, indicating whether the cross-domain Access-Control request should contain authorization information, such as cookies or authorization headers.

XMLHttpRequest.overrideMimeType

  • Description

    Overrides the MIME type returned by the server.