简体   繁体   中英

Asp.Net MVC : Timer not working in IE

I used the following function:

@Using Ajax.BeginForm("Index", New AjaxOptions() With { _
                                                        .UpdateTargetId = "AnswerSN",
                                                        .HttpMethod = "POST"
                                                      })
    @<Script>
         window.setInterval(function () {
             var updateUrl = '@Url.Action("ViewPoints", "Home")';
             $.get(updateUrl, function (result) {
                     initialize(result);
                 });
             }, 30000);

         </script>
    @<div id="AnswerSN" style="position:absolute; top:100px"></div>
End Using

Where to call every 30 seconds the "Viewpoints" controller "Home" icon. I returns every time a result of type json different from the previous one.

Ok , it works in all browsers but not in IE that processes the first time the "Viewpoints" and then processes every 30 seconds the same variable json (obviously returned to the first draft of the "Viewpoints").

How is this possible, if in other browsers I have my desired effect?

Many thanks to those who respond. dave

GET requests cache, set the proper headers or set up jQuery to add the no cache parameter.

$.ajax({
  url: updateUrl,
  success: function(result){
    initialize(result);
  },
  cache: false
});

And it is not wise to use setInterval() with Ajax requests. They can stack up. Make sure to check if a previous request is open and abort it. You can use

timeout: 3000 

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