Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface XMLHttpRequest

Hierarchy

  • XMLHttpRequest

Index

Constructors

constructor

  • Creates a XMLHttpRequest (XHR).

    var xhr = new XMLHttpRequest();
    
    // XHR event handler.
    xhr.onreadystatechange = function() {
    
        // Get xhr states
        var state = this.readyState;
    
        // Only consider the "done" state. Skip others
        if (state !== 4) {
            return;
        }
    
        // Get xhr response headers
        var headers = this.getAllResponseHeaders();
    
        // Get xhr response text contents
        var result = this.responseText;
    
        // Display the result when received
        console.log( result );
    };
    
    // Get server rest info
    // Synchronous xhr request
    xhr.open( 'GET', 'http://127.0.0.1:8081/rest/$info' );
    
    // Send the XHR request
    xhr.send();
    warning

    Sends synchronous XHR request.

    Parameters

    • Optional proxy: Object

      {host: String, port: Number} Overrides the system proxy settings

    Returns XMLHttpRequest

Properties

onreadystatechange

onreadystatechange: function

Defines the event listener function that will handle the various states of the XMLHttpRequest. See [doc center](http://doc.wakanda.org/home2.en.html#/Wakanda Studio/0.Beta/readyState.303-867831.en.html) for more details about xhr states.

Type declaration

readyState

readyState: number

Current state of the request. See [doc center](http://doc.wakanda.org/home2.en.html#/Wakanda Studio/0.Beta/readyState.303-867831.en.html) for more details about xhr states.

response

response: any

Response body part (other than text).

responseText

responseText: string

Text response entity body.

responseType

responseType: string

Data type of the response ("text" or "blob").

status

status: number

HTTP status code of the response.

statusText

statusText: string

HTTP status text of the response.

timeout

timeout: number

Defines a XHR timeout in millisecond. Default is 0 for an infinite timeout.

Methods

getAllResponseHeaders

  • getAllResponseHeaders(): String
  • Returns all HTTP headers from the response of the XMLHttprequest.

    Returns String

getResponseHeader

  • getResponseHeader(header: String): String
  • Returns the value of a specific header field in the response of the XMLHttpRequest.

    Parameters

    • header: String

    Returns String

open

  • open(method: String, url: String): void
  • Declares the HTTP method and the URL of the XMLHttpRequest.

    Parameters

    • method: String

      HTTP method

    • url: String

      URL of the request

    Returns void

send

  • Sends the XHR opened request.

    Example 1: Basic usage

    var xhr = new XMLHttpRequest();
    xhr.open( 'GET', 'http://127.0.0.1:8081/rest/$info' );
    xhr.send();

    Example 2: Upload file

    See doc center for more details about upload

    var xhr = new XMLHttpRequest();
    xhr.open('PUT', 'http://127.0.0.1:8081/rest/$upload?$rawPict=true');
    xhr.setRequestHeader( 'Content-Type', 'image/jpeg' );
    xhr.onreadystatechange = function() {
        if (this.readyState !== 4) {
            return;
        }
        // Displays the upload result ID to use as reference in Wakanda DB
        console.log( 'Upload ID:'+ xhr.responseText );
    }
    xhr.send( 'PROJECT/my-image.jpg' );
    warning

    Sends synchronous XHR request.

    Parameters

    • Optional data: String

      Data to send in the request body

    Returns void

  • Sends the XHR opened request.

    Example 1: Basic usage

    var xhr = new XMLHttpRequest();
    xhr.open( 'GET', 'http://127.0.0.1:8081/rest/$info' );
    xhr.send();

    Example 2: Upload file

    See doc center for more details about upload

    var myFile = new File( 'PROJECT/my-image.jpg' );
    var xhr = new XMLHttpRequest();
    xhr.open('PUT', 'http://127.0.0.1:8081/rest/$upload?$rawPict=true');
    xhr.setRequestHeader( 'Content-Type', 'image/jpeg' );
    xhr.onreadystatechange = function() {
        if (this.readyState !== 4) {
            return;
        }
        // Displays the upload result ID to use as reference in Wakanda DB
        console.log( 'Upload ID:'+ xhr.responseText );
    }
    xhr.send( myFile );
    warning

    Sends synchronous XHR request.

    Parameters

    Returns void

setClientCertificate

  • setClientCertificate(keyPath: String, certificatePath: String): void
  • Allows the request to be authenticated on the remote server with a client certificate, when necessary.

    Parameters

    • keyPath: String

      Path to the PEM format private key

    • certificatePath: String

      Path to the local PEM format certificate

    Returns void

setRequestHeader

  • setRequestHeader(header: String, value: String): void
  • Set the value of a specific header field of the XMLHttpRequest.

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://127.0.0.1:8081/rest/$info');
    xhr.setRequestHeader('X-Test', 'one');
    xhr.setRequestHeader('X-Test', 'two');
    xhr.send();

    Parameters

    • header: String

      The header field name

    • value: String

      The header field value

    Returns void