Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ajax beforesend wait before sending

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

like image 773
user1865928 Avatar asked Oct 15 '25 09:10

user1865928


2 Answers

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;
    }
});
like image 178
jcubic Avatar answered Oct 16 '25 22:10

jcubic


you can try this, put the ajax request into setTimout function

setTimeout(function(){
  //do the ajax request
}, 2000);

good luck!

like image 28
dotarsoyak Avatar answered Oct 16 '25 21:10

dotarsoyak