How to trigger ajax request on scroll stop?

后端 未结 3 1597
星月不相逢
星月不相逢 2021-01-07 04:26

On window scroll I\'m doing ajax request like this

$(window).scroll(function(){
 //doing ajax request
});

but it is creating multiple ajax

3条回答
  •  感动是毒
    2021-01-07 05:08

    This question offers one solution.

    Another way to do this, rather than a timer, is to simply set a flag that indicates that an ajax request is already running, and to do nothing until the flag is cleared by the original request. You could also set a timer after the flag is cleared, if you wanted the ajax requests to not happen any more often than some arbitrary frequency (e.g. no more often than every 5 seconds).

提交回复
热议问题