mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Ajax: add an ontimeout handler to all requests
Fixes gh-3586 Close gh-3590
This commit is contained in:
parent
d65bdd5fc8
commit
262acc6f1e
@ -75,7 +75,8 @@ jQuery.ajaxTransport( function( options ) {
|
||||
return function() {
|
||||
if ( callback ) {
|
||||
callback = errorCallback = xhr.onload =
|
||||
xhr.onerror = xhr.onabort = xhr.onreadystatechange = null;
|
||||
xhr.onerror = xhr.onabort = xhr.ontimeout =
|
||||
xhr.onreadystatechange = null;
|
||||
|
||||
if ( type === "abort" ) {
|
||||
xhr.abort();
|
||||
@ -115,7 +116,7 @@ jQuery.ajaxTransport( function( options ) {
|
||||
|
||||
// Listen to events
|
||||
xhr.onload = callback();
|
||||
errorCallback = xhr.onerror = callback( "error" );
|
||||
errorCallback = xhr.onerror = xhr.ontimeout = callback( "error" );
|
||||
|
||||
// Support: IE 9 only
|
||||
// Use onreadystatechange to replace onabort
|
||||
|
@ -527,6 +527,23 @@ QUnit.module( "ajax", {
|
||||
};
|
||||
} );
|
||||
|
||||
ajaxTest( "jQuery.ajax() - native timeout", 2, function( assert ) {
|
||||
return {
|
||||
url: url( "data/name.php?wait=1" ),
|
||||
xhr: function() {
|
||||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.timeout = 1;
|
||||
return xhr;
|
||||
},
|
||||
error: function( xhr, msg ) {
|
||||
assert.strictEqual( msg, "error", "Native timeout triggers error callback" );
|
||||
},
|
||||
complete: function() {
|
||||
assert.ok( true, "complete" );
|
||||
}
|
||||
};
|
||||
} );
|
||||
|
||||
ajaxTest( "jQuery.ajax() - events with context", 12, function( assert ) {
|
||||
var context = document.createElement( "div" );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user