SetInterval only runs once

拜拜、爱过 提交于 2019-12-11 18:15:53

问题


This is my JavaScript code:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">

function mytest() {

        var jqxhr = $.get("Home/GetMonitorData", function (data) {
        $("#cpu").text(data.cpu);
        $("#dspace").text(data.dspace);
        $("#cspace").text(data.cspace);
        $("#pf").text(data.pf);
        $("#totphysical").text(data.totphysical);
        $("#freephysical").text(data.freephysical);
        $("#tcp").text(data.tcp);
        $("#req").text(data.req);


    }, "json");

}

$(document).ready(function () {
    setInterval(mytest, 3000);
}); 



</script> 

The issue is, setInterval only runs once. My program is supposed to get some WMI Information from an action method, print in on screen, and refresh these values every 3 seconds. But after one refresh, it stops. Any suggestions/ideas?


回答1:


You need to set Request.Expires = 0 when calling ajax.




回答2:


Maybe ajax requests stack because there is no time and then break the chain?

Try increasing the interval size for debugging purposes and see if the situation has changed.



来源:https://stackoverflow.com/questions/7090121/setinterval-only-runs-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!