Search results

Ajax API in JavaScript Base API control

Ajax class provides ability to make asynchronous HTTP request to the server

  var ajax = new Ajax("index.html", "GET", true);
  ajax.send().then(
              function (value) {
                  console.log(value);
              },
              function (reason) {
                  console.log(reason);
              });

Properties

data

string | Object

Specifies the data to be sent.

Defaults to null

httpRequest

XMLHttpRequest

Specifies the callback for creating the XMLHttpRequest object.

Defaults to null

mode

boolean

A boolean value indicating whether the request should be sent asynchronous or not.

Defaults to true

type

string

Specifies which HTTP request method to be used. For ex., GET, POST

Defaults to GET

url

string

Specifies the URL to which request to be sent.

Defaults to null

Methods

getResponseHeader

To get the response header from XMLHttpRequest

Parameter Type Description
key string Key to search in the response header

Returns string

send

Send the request to server.

Parameter Type Description
data (optional) string | Object To send the user data

Returns Promise

Events

beforeSend

Function

Specifies the callback function to be triggered before sending request to sever. This can be used to modify the XMLHttpRequest object before it is sent.

onFailure

Function

Triggers when XmlHttpRequest is failed.

onSuccess

Function

Specifies callback function to be triggered after XmlHttpRequest is succeeded. The callback will contain server response as the parameter.