import Ajax from '@mobilizing/library/js/Mobilizing/net/Ajax.js'
Ajax
Ajax is a helper class used to simplify the use of the XMLHttpRequest API
Example:
//TODO
Static Method Summary
Constructor Summary
Public Constructor | ||
public | constructor(params: Object) |
Member Summary
Method Summary
Public Methods | ||
public | abort() 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 | setResponseType(value: String) Wrapping method for the responseType property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responsetype | |
public | setTimeout(value: Number) Wrapping method for the timeout property of XMLHttpRequest see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/timeout | |
public | setWithCredentials(value: Boolean) 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:
Name | Type | Attribute | Description |
params | Object | Parameters object to pass to the constructor. |
Return:
* |
Public Constructors
public constructor(params: Object) source
Params:
Name | Type | Attribute | Description |
params | Object | Parameters object, given by the constructor. | |
params.url | String | The URL to which the request is sent | |
params.method | String |
| The method used for the request (GET, POST, or PUT) |
params.data | Object |
| Data to be send along with the request |
params.headers | Object |
| An object of header key/value pairs to send along with requests |
params.async | Boolean |
| Whether the request is asynchronous or not |
params.autoSend | Boolean |
| Whether the request should be automatically sent |
params.withCredentials | Boolean |
| Whether cross-site Access-Control requests should be made using credentials such as cookies or authorization headers |
params.responseType | String |
| The responseType this request must return |
params.timeout | Number |
| The number of milliseconds the request can take before automatically being terminated |
params.onReadyStateChange | Function |
| A function to be called when the readyState of the request changes |
params.onStart | Function |
| A function to be called when the request starts |
params.onProgress | Function |
| A function to be called when the request progresses |
params.onLoad | Function |
| A function to be called when the request finishes |
params.onSuccess | Function |
| A function to be called if the request succeeds |
params.onError | Function |
| 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 _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:
Name | Type | Attribute | Description |
data | Mixed | 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
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:
Name | Type | Attribute | Description |
value | String | 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:
Name | Type | Attribute | Description |
value | Number | 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:
Name | Type | Attribute | Description |
value | Boolean | 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