2 * jQuery XDomainRequest Transport Plugin 1.1.2
3 * https://github.com/blueimp/jQuery-File-Upload
5 * Copyright 2011, Sebastian Tschan
8 * Licensed under the MIT license:
9 * http://www.opensource.org/licenses/MIT
11 * Based on Julian Aubourg's ajaxHooks xdr.js:
12 * https://github.com/jaubourg/ajaxHooks/
15 /*jslint unparam: true */
16 /*global define, window, XDomainRequest */
20 if (typeof define === 'function' && define.amd) {
21 // Register as an anonymous AMD module:
22 define(['jquery'], factory);
25 factory(window.jQuery);
29 if (window.XDomainRequest && !$.support.cors) {
30 $.ajaxTransport(function (s) {
31 if (s.crossDomain && s.async) {
33 s.xdrTimeout = s.timeout;
38 send: function (headers, completeCallback) {
39 function callback(status, statusText, responses, responseHeaders) {
40 xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
42 completeCallback(status, statusText, responses, responseHeaders);
44 xdr = new XDomainRequest();
45 // XDomainRequest only supports GET and POST:
46 if (s.type === 'DELETE') {
47 s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
50 } else if (s.type === 'PUT') {
51 s.url = s.url + (/\?/.test(s.url) ? '&' : '?') +
55 xdr.open(s.type, s.url);
56 xdr.onload = function () {
60 {text: xdr.responseText},
61 'Content-Type: ' + xdr.contentType
64 xdr.onerror = function () {
65 callback(404, 'Not Found');
68 xdr.ontimeout = function () {
69 callback(0, 'timeout');
71 xdr.timeout = s.xdrTimeout;
73 xdr.send((s.hasContent && s.data) || null);
77 xdr.onerror = $.noop();