Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions jquery.iecors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,69 @@

return {
send: function( headers, complete ) {
// Get a new xdr
var xdr = s.xdr();

xdr.onload = function() {
var headers = { 'Content-Type': xdr.contentType };
complete(200, 'OK', { text: xdr.responseText }, headers);
var status, responseHeaders, statusText, responses;

// Firefox throws exceptions when accessing properties
// of an xdr when a network error occurred
// http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
try {

responses = {};
// IE8 does not set status at all.
status = xdr.status || 200;
if (xdr.contentType) {
responseHeaders = { 'Content-Type': xdr.contentType };
if (xdr.contentType.toLowerCase().indexOf("application/json") == 0)
s.dataTypes.push("json");
}

// When requesting binary data, IE6-9 will throw an exception
// on any attempt to access responseText (#11426)
if ( typeof xdr.responseText === "string" ) {
responses.text = xdr.responseText;
}

// Firefox throws an exception when accessing
// statusText for faulty cross-domain requests
try {
statusText = xdr.statusText || "OK";
} catch( e ) {
// We normalize with Webkit giving an empty statusText
status = 0;
statusText = "";
}

// Filter status for non standard behaviors

// If the request is local and we have data: assume a success
// (success with no data won't get notified, that's the best we
// can do given current implementations)
if ( !status && s.isLocal && !s.crossDomain ) {
status = responses.text ? 200 : 404;
// IE - #1450: sometimes returns 1223 when it should be 204
} else if ( status === 1223 ) {
status = 204;
}

} catch( firefoxAccessException ) {
complete( -1, firefoxAccessException );
}

// Call complete if needed
if ( responses ) {
complete( status, statusText, responses, responseHeaders );
}
};

// Apply custom fields if provided
if ( s.xhrFields ) {
xhr.onerror = s.xhrFields.error;
xhr.ontimeout = s.xhrFields.timeout;
}
if ( s.xhrFields ) {
xdr.onerror = s.xhrFields.error;
xdr.ontimeout = s.xhrFields.timeout;
}

xdr.open( s.type, s.url );

Expand Down