这是我的JavaScript代码:的setInterval只运行一次
<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>
的问题是,setInterval的仅运行一次。我的程序应该从操作方法中获取一些WMI信息,并在屏幕上打印,并每3秒刷新一次这些值。但一次刷新后,它会停止。任何建议/想法?
我发现setInterval无法连续运行时,这是由于定时器函数中的javascript错误(至少,这是FireFox所做的)。你检查了JavaScript错误日志? –