mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-14 20:35:47 +01:00
Split out ajax extension
This commit is contained in:
committed by
Jörn Zaefferer
parent
2f4b5b99c2
commit
0bce286762
33
src/core.js
33
src/core.js
@@ -1181,36 +1181,3 @@ $.format = $.validator.format;
|
||||
|
||||
}(jQuery));
|
||||
|
||||
// ajax mode: abort
|
||||
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
|
||||
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
|
||||
(function($) {
|
||||
var pendingRequests = {};
|
||||
// Use a prefilter if available (1.5+)
|
||||
if ( $.ajaxPrefilter ) {
|
||||
$.ajaxPrefilter(function( settings, _, xhr ) {
|
||||
var port = settings.port;
|
||||
if ( settings.mode === "abort" ) {
|
||||
if ( pendingRequests[port] ) {
|
||||
pendingRequests[port].abort();
|
||||
}
|
||||
pendingRequests[port] = xhr;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Proxy ajax
|
||||
var ajax = $.ajax;
|
||||
$.ajax = function( settings ) {
|
||||
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
|
||||
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
|
||||
if ( mode === "abort" ) {
|
||||
if ( pendingRequests[port] ) {
|
||||
pendingRequests[port].abort();
|
||||
}
|
||||
pendingRequests[port] = ajax.apply(this, arguments);
|
||||
return pendingRequests[port];
|
||||
}
|
||||
return ajax.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
}(jQuery));
|
||||
|
||||
Reference in New Issue
Block a user