xhr = $.ajax;
xhr({
success: fun开发者_JAVA技巧ction(){ ajaxProcess = false; },
beforeSend : function (i) {
if(ajaxProcess==true)
xhr.abort();
else
ajaxProcess = true;
}
});
$('.button').click(function(){
$.getJSON('file.php', function(data){});
};
$('.button2').click(function(){
$.getJSON('file.php', function(data){});
};
Use the global ajaxSend
handler
http://api.jquery.com/ajaxSend/
EDIT
To stop all executing requests, you can do something like the following. Create an array of request objects. Then in the the global ajaxSend
handler you can add the request to the array and do your check. If the check succeeds, iterate through the array and abort all of the requests. Then you can create a global ajaxStop
handler that removes the requests from the request array as they finish executing.
精彩评论