Fixes comments per @rwldrn. Makes sure failing requests from local protocol yields status 404, not 0.

This commit is contained in:
jaubourg 2013-01-06 00:41:08 +01:00 committed by Dave Methvin
parent 17049c73bc
commit f6df0301c8

View File

@ -8,7 +8,8 @@ var xhrSupported = jQuery.ajaxSettings.xhr(),
xhrSuccessStatus = { xhrSuccessStatus = {
// file protocol always yields status code 0, assume 200 // file protocol always yields status code 0, assume 200
0: 200, 0: 200,
// IE - #1450: sometimes returns 1223 when it should be 204 // Support: IE9
// #1450: sometimes IE returns 1223 when it should be 204
1223: 204 1223: 204
}; };
@ -23,7 +24,6 @@ jQuery.ajaxTransport(function( options ) {
send: function( headers, complete ) { send: function( headers, complete ) {
var i, var i,
xhr = options.xhr(); xhr = options.xhr();
// Open the socket
xhr.open( options.type, options.url, options.async, options.username, options.password ); xhr.open( options.type, options.url, options.async, options.username, options.password );
// Apply custom fields if provided // Apply custom fields if provided
if ( options.xhrFields ) { if ( options.xhrFields ) {
@ -55,13 +55,18 @@ jQuery.ajaxTransport(function( options ) {
if ( type === "abort" ) { if ( type === "abort" ) {
xhr.abort(); xhr.abort();
} else if ( type === "error" ) { } else if ( type === "error" ) {
complete( xhr.status, xhr.statusText ); complete(
// file protocol always yields status 0, assume 404
xhr.status || 404,
xhr.statusText
);
} else { } else {
complete( complete(
xhrSuccessStatus[ xhr.status ] || xhr.status, xhrSuccessStatus[ xhr.status ] || xhr.status,
xhr.statusText, xhr.statusText,
// IE - #11426: When requesting binary data, IE9 will // Support: IE9
// throw an exception on any attempt to access responseText // #11426: When requesting binary data, IE9 will throw an exception
// on any attempt to access responseText
typeof xhr.responseText === "string" ? { typeof xhr.responseText === "string" ? {
text: xhr.responseText text: xhr.responseText
} : undefined, } : undefined,
@ -81,7 +86,6 @@ jQuery.ajaxTransport(function( options ) {
// handled in jQuery.ajax (so no try/catch here) // handled in jQuery.ajax (so no try/catch here)
xhr.send( options.hasContent && options.data || null ); xhr.send( options.hasContent && options.data || null );
}, },
abort: function() { abort: function() {
if ( callback ) { if ( callback ) {
callback(); callback();