Trying to add delay to jQuery AJAX request

后端 未结 3 1800
余生分开走
余生分开走 2021-02-06 08:28

I am trying to delay an AJAX request so that it is sent out 2-3 seconds after the LAST keyup of an input cell.
So far I have managed to delay the requests, but after 2-3 sec

3条回答
  •  攒了一身酷
    2021-02-06 09:02

    store the timeout in a variable, so you will be able to clear recent timeouts:

    clearTimeout(window.timer);
    window.timer=setTimeout(function(){ // setting the delay for each keypress
                    ajaxSearchRequest($type); //runs the ajax request
    
            }, 3000);
    

提交回复
热议问题