Repository

Ajax

Ajax is a helper class used to simplify the use of the XMLHttpRequest API

Example:

   //TODO

Static Method Summary

Static Public Methods
public static

get(params: Object): *

A helper function to create a request of type GET

public static

post(params: Object): *

A helper function to create a request of type POST

public static

put(params: Object): *

A helper function to create a request of type PUT

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

async: *

public
public

data: *

public

events: *

public
public

method: *

public
public

onLoad: *

public
public
public
public
public
public
public

url: *

public
Private Members
private

_data: *

private
private

_xhr: *

Method Summary

Public Methods
public

Wrapping method for abort method of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort

public

Return the XMLHttpRequest responseText as a JSON object

public

Wrapping method for readyState property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState

public

getResponse(): Mixed

Wrapping method for response property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response

public

Wrapping method for responseText property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText

public

Wrapping method for responseType property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

public

Wrapping method for status property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status

public

getStatusText(): DOMString

Wrapping method for statusText property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/statusText

public

getXHR(): XMLHttpRequest

Get the XMLHttpRequest instance for the request see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

public

send(data: Mixed)

Wrapping method for the send method of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send

public

setRequestHeader(header: String, value: String)

Wrapping method for the setRequestHeader method of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader

public

Wrapping method for the responseType property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responsetype

public

Wrapping method for the timeout property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout

public

Wrapping method for the withCredentials property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

Private Methods
private

The readystatechange event handler

Static Public Methods

public static get(params: Object): * source

A helper function to create a request of type GET

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the constructor.

Return:

*

public static post(params: Object): * source

A helper function to create a request of type POST

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the constructor.

Return:

*

public static put(params: Object): * source

A helper function to create a request of type PUT

Params:

NameTypeAttributeDescription
paramsObject

Parameters object to pass to the constructor.

Return:

*

Public Constructors

public constructor(params: Object) source

Params:

NameTypeAttributeDescription
paramsObject

Parameters object, given by the constructor.

params.urlString

The URL to which the request is sent

params.methodString
  • optional
  • default: "GET"

The method used for the request (GET, POST, or PUT)

params.dataObject
  • optional
  • default: null

Data to be send along with the request

params.headersObject
  • optional
  • default: null

An object of header key/value pairs to send along with requests

params.asyncBoolean
  • optional
  • default: true

Whether the request is asynchronous or not

params.autoSendBoolean
  • optional
  • default: true

Whether the request should be automatically sent

params.withCredentialsBoolean
  • optional
  • default: null

Whether cross-site Access-Control requests should be made using credentials such as cookies or authorization headers

params.responseTypeString
  • optional
  • default: ""

The responseType this request must return

params.timeoutNumber
  • optional
  • default: null

The number of milliseconds the request can take before automatically being terminated

params.onReadyStateChangeFunction
  • optional
  • default: null

A function to be called when the readyState of the request changes

params.onStartFunction
  • optional
  • default: null

A function to be called when the request starts

params.onProgressFunction
  • optional
  • default: null

A function to be called when the request progresses

params.onLoadFunction
  • optional
  • default: null

A function to be called when the request finishes

params.onSuccessFunction
  • optional
  • default: null

A function to be called if the request succeeds

params.onErrorFunction
  • optional
  • default: null

A function to be called if the request fails

Public Members

public async: * source

public autoSend: * source

public data: * source

public events: * source

public headers: * source

public method: * source

public onError: * source

public onLoad: * source

public onProgress: * source

public onReadyStateChange: * source

public onStart: * source

public onSuccess: * source

public responseType: * source

public timeout: * source

public url: * source

public withCredentials: * source

Private Members

private _data: * source

private _url: string source

private _xhr: * source

Public Methods

public abort() source

Wrapping method for abort method of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort

public getJSON(): Object source

Return the XMLHttpRequest responseText as a JSON object

Return:

Object

The responseText parsed as a JSON object

public getReadyState(): Number source

Wrapping method for readyState property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState

Return:

Number

The state the XMLHttpRequest client is in

public getResponse(): Mixed source

Wrapping method for response property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response

Return:

Mixed

The response"s body

public getResponseText(): String source

Wrapping method for responseText property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText

Return:

String

The text response

public getResponseType(): String source

Wrapping method for responseType property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType

Return:

String

The response"s type

public getStatus(): Number source

Wrapping method for status property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/status

Return:

Number

The status of the request

public getStatusText(): DOMString source

Wrapping method for statusText property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/statusText

Return:

DOMString

The status message of the request

public getXHR(): XMLHttpRequest source

Get the XMLHttpRequest instance for the request see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Return:

XMLHttpRequest

The XMLHttpRequest instance

public send(data: Mixed) source

Wrapping method for the send method of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send

Params:

NameTypeAttributeDescription
dataMixed

The data to send along the request

public setRequestHeader(header: String, value: String) source

Wrapping method for the setRequestHeader method of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader

Params:

NameTypeAttributeDescription
headerString

The name of the header

valueString

The value of the header

public setResponseType(value: String) source

Wrapping method for the responseType property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responsetype

Params:

NameTypeAttributeDescription
valueString

The type of response to be given by this request. Possible values are : "arraybuffer", "text", "json", "document", "blob"

public setTimeout(value: Number) source

Wrapping method for the timeout property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout

Params:

NameTypeAttributeDescription
valueNumber

The number of milliseconds the request can take before automatically being terminated

public setWithCredentials(value: Boolean) source

Wrapping method for the withCredentials property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

Params:

NameTypeAttributeDescription
valueBoolean

Whether cross-site Access-Control requests should be made using credentials such as cookies or authorization headers

Private Methods

private onXHRReadyStateChange() source

The readystatechange event handler