setInterval stops after Ajax request

前端 未结 7 2163
不知归路
不知归路 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:36

    I'm not sure why that would happen, but I have had similar issues in the past with jQuery Ajax refreshes and setInterval. In the end, I switched to a repeating setTimeout and didn't have any problems:

    function onLoad() {
        setTimeout(ajaxRefresh, 1000);
    } 
    
    function ajaxRefresh()
    {
        var f = $("#AjaxForm");
        $("#AjaxLoading").show();
        $.post(f.attr("action"), f.serialize(), function (context) {
            $("#AjaxDiv").html(context);
            $("#AjaxLoading").hide();
        });
        setTimeout(ajaxRefresh, 1000);
    }
    

提交回复
热议问题