I am trying to use settimeout in the ajaxsetup beforesend function, but what seems to happen is the ajax is sent and the wait function is called after the timeout. I want to stop the requests from sending for the timeout period
jQuery.ajaxSetup({
beforeSend: function(){
setTimeout(continueExecution,1000)
return true;
}
});
Can someone suggest me a way to stop the requests from being sent from ajaxsetup
You can return false to cancel ajax request and create new one in setTimeout callback:
$.ajaxSetup({
beforeSend: function(jqXHR, options) {
setTimeout(function() {
// null beforeSend to prevent recursive ajax call
$.ajax($.extend(options, {beforeSend: $.noop}));
}, 5000);
return false;
}
});
you can try this, put the ajax request into setTimout function
setTimeout(function(){
//do the ajax request
}, 2000);
good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With