Module: UWA/Ajax

UWA/Ajax

API around the XmlHttpRequest object that enables you to deal with Ajax calls in a manner that is both easy and compatible with all modern browsers.

UWA.Data.request provide a Cross-domain Ajax solution that allow you to fetch data through Ajax even if your app is not on the same domain than your request. That why you should not use UWA.Ajax methods as it* but UWA.Data.request method to perform Ajax calls into your app.

Index

Methods

<static> UWA.Ajax.getRequest(url, options) → {XMLHttpRequest}

Create a new XMLHttpRequest object.

Note on "cors" option: CORS is refering to "Cross-Origin Resource Sharing", that allow you to make cross domain AJAX request, to enable it, the server that you request using AJAX need to return following headers:

Access-Control-Allow-Origin: *

Access-Control-Allow-Headers: X-Requested-With

Note that on some Platforms (IE Based), the headers and cookies cannot be set and will be not received by the server and can cause some authentication issues. It is also not possible to make synchronous request on these Platforms.

Note on "responseType" option: responseType value "json" and "document" work on all major browsers, where "blob" and "arraybuffer" require IE 10+

Parameters
Name Type Description
url String

The url to request

options Object

Settings object

Properties
Name Type Argument Default Description
onComplete Function

Callback receiving the Ajax response

method String <optional>
GET

GET, POST (in uppercase!)

data Object <optional>
{}

GET or POST params as object

authentication Object <optional>

Authentication object

headers Object <optional>

Headers object.

timeout Number <optional>

Set your request timeout in ms

onTimeout Function <optional>

Choose your own method

onFailure Function <optional>

Choose your own method

onCancel Function <optional>

Choose your own method

onProgress Function <optional>

progress callback, if the browser supports it

async Boolean <optional>
true

Asynchronous request

cors cors <optional>

Use Cross-Origin Resource Sharing

responseType String <optional>

Type/Format request response (supported: json, document, arraybuffer, blob).

Returns
Type
XMLHttpRequest
See:

<static> UWA.Ajax.createRequest() → {XMLHttpRequest}

Create an XMLHttpRequest request object.

Note: Use feature detection and fallback on Msxml2.XMLHTTP if XMLHttpRequestdoes does not exist.

Returns
Type
XMLHttpRequest

<static> UWA.Ajax.createCORSRequest() → {XMLHttpRequest|XDomainRequest}

Create an XMLHttpRequest Cross-Origin Resource Sharing request object.

Note: Use feature detection and fallback on XDomainRequest if XMLHttpRequest does not support CORS.

Returns
Type
XMLHttpRequest | XDomainRequest
See:

<static> UWA.Ajax.request() → {XMLHttpRequest}

Initiates an Ajax request using UWA.Ajax.getRequest and send it.

See UWA.Ajax.getRequest for parameters.

Returns
Type
XMLHttpRequest

<static> parseResponseHeaders(headerStr) → {Object}

Parse headers from string to an hash.

Example
var request = Ajax.request("http://example.com");
var requestHeaders =  Ajax.parseResponseHeaders(request.getAllResponseHeaders());
// requestHeaders example value: {"Content-Type": "text/html", ...}
Parameters
Name Type Description
headerStr String
Returns
Type
Object