internet explorer - Jquery SetInterval Not Working Correctly in Chrome and IE but is fine in FireFox -


i have jquery/javascript below works fine in firefox doesn't work in chrome , ie

<script type="text/javascript">         (function($) {          $(document).ready(function() {              setinterval(function() {                 $.ajax({                     type: 'get',                     url: "/items/xml/?page={{ pageno }}",                     datatype: 'html',                     success: function(html, textstatus) {                         $('table.items').replacewith(html);                     },                     error: function(xhr, textstatus, errorthrown) {                         if (xhr.status != 0)                         {                         $('table.items').replacewith("<p />an error occurred: " + ( errorthrown ? errorthrown : xhr.status ));                         }                     }                 });              }, 1000);              });          })(jquery);     </script> 

i updated jquery version. v1.10.2 seen suggested on question. sadly didn't work. chrome work of time there times doesn't work @ same ie , slow.

does have code or it's problem in chrome , ie? since firefox fine.

edit:

i should been clear code refreshing update page see changes been made in database. ie new item has been added , code make sure it's seen it's refreshes without making having press f5 or reloading page. mean stays saying it's loading information page in chrome of time displays no information items on page or slow in doing so. same ie. again no problem in firefox.

updated answer:

you've updated problem don't see updated information.

you're using http get, means browser welcome cache result of call if likes, unless specify appropriate cache control headers in response. browsers cache xhr results, others don't.

your best bet make get return appropriate headers. however, can force get bypass cache, using jquery's cache: false flag on ajax call.


original answer:

you haven't said "doesn't work," if it's you're seeing updates happening @ odd intervals, that's not surprising.

your code start ajax request once second (!). ajax request complete time later. how later depend entirely on user's network connection. things very, become chaotic, potentially multiple outstanding requests, multiple responses coming in 1 right after another, etc.

i recommend initiating next request when current 1 completes, this:

(function ($) {     $(document).ready(function () {         function dorequest() {             $.ajax({                 type: 'get',                 url: "/items/xml/?page={{ pageno }}",                 datatype: 'html',                 success: function (html, textstatus) {                     $('table.items').replacewith(html);                 },                 error: function (xhr, textstatus, errorthrown) {                     if (xhr.status != 0) {                         $('table.items').replacewith("<p />an error occurred: " + (errorthrown ? errorthrown : xhr.status));                     }                 },                 complete: schedulerequest // <=== schedule next on completion             });         }          function schedulerequest() {             settimeout(dorequest, 1000);         }          schedulerequest();     }); })(jquery); 

i'd suggest once second firing off network events unless absolutely necessary.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -