Simplifies status normalization in xhr transport. Local file test modified for clarity.
This commit is contained in:
parent
43a41ba7ec
commit
3a1d7a3c7c
|
@ -166,35 +166,14 @@ if ( jQuery.support.ajax ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter status for non standard behaviors
|
// Filter status for non standard behaviors
|
||||||
|
status =
|
||||||
|
// 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)
|
||||||
|
!status && s.isLocal ?
|
||||||
|
( responses.text ? 200 : 404 ) :
|
||||||
// IE - #1450: sometimes returns 1223 when it should be 204
|
// IE - #1450: sometimes returns 1223 when it should be 204
|
||||||
if ( status === 1223 ) {
|
( status === 1223 ? 204 : status );
|
||||||
status = 204;
|
|
||||||
// Various - #8177: a Not Modified response was received
|
|
||||||
// yet no conditional request headers was provided
|
|
||||||
} else if ( status === 304 &&
|
|
||||||
!headers[ "if-modified-since" ] &&
|
|
||||||
!headers[ "if-none-match" ] ) {
|
|
||||||
status = 200;
|
|
||||||
// Status 0 encompasses several cases
|
|
||||||
} else if ( !status ) {
|
|
||||||
// Cross-domain
|
|
||||||
if ( s.crossDomain ) {
|
|
||||||
if ( !s.statusText ) {
|
|
||||||
// FF, Webkit (other?): There is no status text for errors
|
|
||||||
// 302 is the most generic cross-domain status code
|
|
||||||
// for errors, could be anything really (even a real 0)
|
|
||||||
status = 302;
|
|
||||||
}
|
|
||||||
// All same-domain: for local files, 0 is a success
|
|
||||||
} else if( s.isLocal ) {
|
|
||||||
status = 200;
|
|
||||||
// Opera: this notifies success for all requests
|
|
||||||
// (verified in 11.01). Patch welcome.
|
|
||||||
}
|
|
||||||
// Opera - #6060: sets status as 0 for 304
|
|
||||||
// Patch welcome.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch( firefoxAccessException ) {
|
} catch( firefoxAccessException ) {
|
||||||
|
|
|
@ -27,20 +27,25 @@
|
||||||
.success { color: green; }
|
.success { color: green; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>jQuery Local File Test</h1>
|
<h1>jQuery Local File Test</h1>
|
||||||
|
<h2>
|
||||||
|
Introduction
|
||||||
|
</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
Access this file using the "file:" protocol,
|
Access this file using the "file:" protocol,
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
two "OK" strings must appear below,
|
two green "OK" strings must appear below,
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Opera will fail at detecting errors, it's a known issue.
|
Empty local files will issue errors, it's a known limitation.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<h2>
|
||||||
|
Results
|
||||||
|
</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
Success:
|
Success:
|
||||||
|
@ -53,26 +58,35 @@
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<h2>
|
||||||
|
Logs:
|
||||||
|
</h2>
|
||||||
|
<ul id="log">
|
||||||
|
</ul>
|
||||||
<script>
|
<script>
|
||||||
|
var logUL = jQuery( "#log" );
|
||||||
|
function doLog( message, args ) {
|
||||||
|
jQuery( "<li />").appendTo( logUL ).text( message + ': "' + Array.prototype.join.call( args, '" - "' ) + '"' );
|
||||||
|
}
|
||||||
jQuery.ajax( "./data/badjson.js" , {
|
jQuery.ajax( "./data/badjson.js" , {
|
||||||
context: jQuery( "#success" ),
|
context: jQuery( "#success" ),
|
||||||
dataType: "text"
|
dataType: "text"
|
||||||
}).success(function() {
|
}).success(function( data, _, xhr ) {
|
||||||
console && console.log && console.log( "success/success" , arguments );
|
doLog( "Success (" + xhr.status + ")" , arguments );
|
||||||
this.addClass("success").text( "OK" );
|
this.addClass( data ? "success" : "error" ).text( "OK" );
|
||||||
}).error(function() {
|
}).error(function( xhr ) {
|
||||||
console && console.log && console.log( "success/error" , arguments );
|
doLog( "Success (" + xhr.status + ")" , arguments );
|
||||||
this.addClass("error").text( "FAIL" );
|
this.addClass( "error" ).text( "FAIL" );
|
||||||
});
|
});
|
||||||
jQuery.ajax( "./data/doesnotexist.ext" , {
|
jQuery.ajax( "./data/doesnotexist.ext" , {
|
||||||
context: jQuery( "#error" ),
|
context: jQuery( "#error" ),
|
||||||
dataType: "text"
|
dataType: "text"
|
||||||
}).error(function() {
|
}).error(function( xhr ) {
|
||||||
console && console.log && console.log( "error/error" , arguments );
|
doLog( "Error (" + xhr.status + ")" , arguments );
|
||||||
this.addClass("success").text( "OK" );
|
this.addClass( "success" ).text( "OK" );
|
||||||
}).success(function() {
|
}).success(function( data, _, xhr ) {
|
||||||
console && console.log && console.log( "error/success" , arguments );
|
doLog( "Error (" + xhr.status + ")" , arguments );
|
||||||
this.addClass( $.browser.opera ? "success" : "error" ).text( "FAIL" );
|
this.addClass( "error" ).text( "FAIL" );
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
Loading…
Reference in a new issue