简体   繁体   中英

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. I need to support >IE7, and other major browsers.

The setInterval function is getting fired in all the browsers except IE7 and IE8.

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. 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. When creating the element, I wrapped the class keyword in quotes and all is well. Thanks Pointy for asking me to look at the console. @Spudley, thanks for the tip, I will be refactoring my code with your suggestion.

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