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
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 urlString The url to request
optionsObject Settings object
Properties
Name Type Argument Default Description onCompleteFunction Callback receiving the Ajax response
methodString <optional>
GET GET, POST (in uppercase!)
dataObject <optional>
{} GET or POST params as object
authenticationObject <optional>
Authentication object
headersObject <optional>
Headers object.
timeoutNumber <optional>
Set your request timeout in ms
onTimeoutFunction <optional>
Choose your own method
onFailureFunction <optional>
Choose your own method
onCancelFunction <optional>
Choose your own method
onProgressFunction <optional>
progress callback, if the browser supports it
asyncBoolean <optional>
true Asynchronous request
corscors <optional>
Use Cross-Origin Resource Sharing
responseTypeString <optional>
Type/Format request response (supported: json, document, arraybuffer, blob).
Returns
- Type
- XMLHttpRequest
-
<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
-
<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 headerStrString Returns
- Type
- Object