setInterval stops after Ajax request

前端 未结 7 2107
不知归路
不知归路 2021-01-03 15:50

I\'m using Asp.net MVC and I want my partial view to refresh on an interval, which it does until I make an unrelated Ajax request, then it stops.

Here are a few simp

相关标签:
7条回答
  • 2021-01-03 16:39

    i wouldn't use setInterval to update the content, as if the content takes more than 1 second to load, you'll have multiple requests in queue..

    use setTimeout after the request is complete

    function sendRequest(){
        $.ajax({
           /** your post data code **/
           complete : function(xhr, status){
                          setTimeout('sendRequest',1000);
                     }
        });
    }
    

    this way the second request wouldn't be made before the first one finishes. and this should solve your problem too.

    0 讨论(0)
提交回复
热议问题