SetInterval 仅运行一次
这是我的 JavaScript 代码:
<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 秒刷新这些值。但刷新一次后就停止了。有什么建议/想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用ajax时需要设置
Request.Expires = 0
。You need to set
Request.Expires = 0
when calling ajax.也许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.