简体   繁体   English

Javascript setInterval在IE7和IE8中不起作用

[英]Javascript setInterval not working in IE7 and IE8

I am using the Javascript setInterval to keep polling the server for any updates and refresh the screen with the response from the server. 我正在使用Javascript setInterval来继续轮询服务器是否有任何更新,并使用服务器的响应刷新屏幕。 I need to support >IE7, and other major browsers. 我需要支持> IE7和其他主要浏览器。

The setInterval function is getting fired in all the browsers except IE7 and IE8. 在除IE7和IE8之外的所有浏览器中都会触发setInterval函数。

According to the suggestions I saw in other posts I have tried setting cache:false on the ajax requests as well as wrapping the setInterval call in an anonymous function. 根据我在其他帖子中看到的建议,我尝试在ajax请求上设置cache:false,并将setInterval调用包装在匿名函数中。 But none of the suggestions seem to work. 但是这些建议似乎都不起作用。

Following is the code I am using: 以下是我正在使用的代码:

$(document).ready(function () {
    setInterval(pollForServerUpdates, 30000);
});


function pollForServerUpdates() {

$.ajax({ url: $.url("Home/GetUpdates"),
        type: "POST",
        cache: false,
        success: function (result) {
            updateTabelWithCurrentStatus(result);
        },
        dataType: "json"
    });    
}

I am not sure if I am missing anything here. 我不确定在这里是否缺少任何东西。 Any help is very much appreciated. 很感谢任何形式的帮助。 Thanks! 谢谢!

I am putting my comments above as the answer to this question. 我把我的评论作为对这个问题的答案。 The issue was happening because "class" seems to be a reserved keyword in IE and causing an error. 发生问题是因为“类”似乎是IE中的保留关键字,并导致错误。 When creating the element, I wrapped the class keyword in quotes and all is well. 创建元素时,我将class关键字用引号引起来,一切都很好。 Thanks Pointy for asking me to look at the console. 感谢Pointy要求我查看控制台。 @Spudley, thanks for the tip, I will be refactoring my code with your suggestion. @Spudley,感谢您的提示,我将根据您的建议重构代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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