简体   繁体   中英

SetInterval only runs once

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM