setInterval stops after Ajax request

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

    If your AjaxRefresh.js has just the code you showed us, you can use this code. When the browser call the .js it will start functioning.

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

提交回复
热议问题