Brings CORS (Cross-origin resource sharing) support to Tire. Extends the Ajax settings in Tire.
Important: Requires Tire 1.2.0 or newer.
typeHTTP request method. GET is default.urlURL to which the request is made.dataData for the request. Non-string objects will get serialized with$.paramcontentTypeWhich content type to post to server. Default isapplication/x-www-form-urlencoded.dataTypeResponse type to expect from the server. Default is none. Can bejson, jsonp, xml, html, text.headersObject of additional HTTP headers for the Ajax request.successThe function to execute when the request is done with data as a argument.errorThe function to execute on error with error arguments.timeoutSet a timeout in milliseconds for the request.beforeOpenNot supported with CORS.beforeSendModify the xhr object before sending it. Returnfalseto prevent the request from being sent. Default isnull.
crossDomain: true/falseDefault isfalse.xhrFields: { withCredentials: true/false }Default isfalse.
$(function () {
$.ajax({
type: 'GET',
url: 'http://updates.html5rocks.com',
contentType: 'text/plain',
success: function (res) {
$('body').html(res);
},
error: function () {
$('body').html('<span style="color:red">Error loading HTML5Rocks!</span>');
}
});
});If a URL contains callback=?, callback=string or dataType is jsonp it will be a JSONP request. The response data will automatic be parsed as a JSON object if it's a JSONP or JSON request.
Don't use beforeOpen as it disables the CORS support.
Support for CORS in IE8/9 is limited. Please read the article XDomainRequest - Restrictions, Limitations and Workarounds carefully and comply to those limitations if you need to support those browsers.