API Documentation

for 0.0.1
Show:

Ajax Class

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

Constructor

Ajax

(
  • params
)

Parameters:

  • params Object

    The parameters object

    • url String

      The URL to which the request is sent

    • [method= "GET"] String optional

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

    • [data= null] Object optional

      Data to be send along with the request

    • [headers= null] Object optional

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

    • [async= true] Boolean optional

      Whether the request is asynchronous or not

    • [autoSend= true] Boolean optional

      Whether the request should be automatically sent

    • [withCredentials= null] Boolean optional

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

    • [responseType= ""] String optional

      The responseType this request must return

    • [timeout= null] Number optional

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

    • [onReadyStateChange= null] Function optional

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

    • [onStart= null] Function optional

      A function to be called when the request starts

    • [onProgress= null] Function optional

      A function to be called when the request progresses

    • [onLoad= null] Function optional

      A function to be called when the request finishes

    • [onSuccess= null] Function optional

      A function to be called if the request succeeds

    • [onError= null] Function optional

      A function to be called if the request fails

Example:

//TODO

Methods

abort

()

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

get

(
  • params
)
static

A helper function to create a request of type GET

Parameters:

  • params Object

    The parameters to send to the constructor

getJSON

() Object

Return the XMLHttpRequest responseText as a JSON object

Returns:

Object:

The responseText parsed as a JSON object

getReadyState

() Number

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

Returns:

Number:

The state the XMLHttpRequest client is in

getResponse

() Mixed

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

Returns:

Mixed:

The response's body

getResponseText

() String

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

Returns:

String:

The text response

getResponseType

() String

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

Returns:

String:

The response's type

getStatus

() Number

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

Returns:

Number:

The status of the request

getStatusText

() DOMString

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

Returns:

DOMString:

The status message of the request

getXHR

() XMLHttpRequest

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

Returns:

XMLHttpRequest:

The XMLHttpRequest instance

onReadyStateChange

() private

The readystatechange event handler

post

(
  • params
)
static

A helper function to create a request of type POST

Parameters:

  • params Object

    The parameters to send to the constructor

put

(
  • params
)
static

A helper function to create a request of type PUT

Parameters:

  • params Object

    The parameters to send to the constructor

send

(
  • data
)

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

Parameters:

  • data Mixed

    The data to send along the request

setRequestHeader

(
  • header
  • value
)

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

Parameters:

  • header String

    The name of the header

  • value String

    The value of the header

setResponseType

(
  • value
)

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

Parameters:

  • value String

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

setTimeout

(
  • value
)

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

Parameters:

  • value Number

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

setWithCredentials

(
  • value
)

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

Parameters:

  • value Boolean

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

Events

error

Fired when the request encountered an error, or if it finished loading with an error status

Event Payload:

  • ajax Ajax

    The Ajax instance

load

Fired when the request has finished loading

Event Payload:

  • ajax Ajax

    The Ajax instance

  • success Boolean

    Whether the request was successfull or not

progress

Fired when an operation is in progress

Event Payload:

  • ajax Ajax

    The Ajax instance

readystatechange

Fired when the readystate of the request changes

Event Payload:

  • ajax Ajax

    The Ajax instance

start

Fired when the request is opened

Event Payload:

  • ajax Ajax

    The Ajax instance

success

Fired when the request has finished loading and the status is greater or equal to 200 and less than 300, or is equal to 304

Event Payload:

  • ajax Ajax

    The Ajax instance