1

I am trying to make chat which must work in Internet Explorer. Code for content refresh is below (I know it could be made better way, but it works in every other browser...)

But in IE, script is working (I mean it's doing that refresh), but content is still the same. Even if I write something to the file "chat_vypis.php"... When I try to refresh it with F5, it doesn't work as well... In "chat_vypis.php" is only SELECT query and echo with result. You can check it at sdbt.mobydyk.cz .

Here is script for refresh, thank you for every advice!

<script type="text/javascript">
$(document).ready(function(){ 

    var auto= $('#chat');
    var refreshed_content;  
        refreshed_content = setInterval(function(){
        auto.load("chat_vypis.php");}, 
        1000);                                      
        console.log(refreshed_content);                                      
        return false; 
});
</script>
H Sturma
  • 301
  • 4
  • 17
  • did you try location.reload(); – damitj07 Mar 21 '16 at 09:40
  • Solved with adding random number after link to chat_vypis.php. Solution found here: http://stackoverflow.com/questions/1061525/jquerys-load-not-working-in-ie-but-fine-in-firefox-chrome-and-safari – H Sturma Mar 21 '16 at 09:43

2 Answers2

0

IE is maybe caching the ajax request and doesn't even send them. Try:

$.ajaxSetup({ cache: false });

at the start of your document ready function

Ulrich
  • 1
0

Two things you can do:

1) Disable all AJAX caching. You probably don't want to do this as it disables all jQuery caching for every ajax request you make within the same page unless you manually set "cache": true in all other ajax requests.

$(document).ready(function () {
    $.ajaxSetup ({
         cache: false
    });
});

2) Trick the browser into thinking you're requesting a different page each time (note this is what turning AJAX cache off does behind the scenes for every request anyway).:

<script type="text/javascript">
$(document).ready(function(){ 

    var auto= $('#chat');
    var refreshed_content;  
        refreshed_content = setInterval(function() {
            auto.load("chat_vypis.php?_="+Math.floor((Math.random() * 1000000) + 1));
        }, 1000);                                      
        console.log(refreshed_content);                                      
        return false; 
});
</script>

In theory you can also put this on the server side (on the top, before any output is opened):

<?php
header("Cache-Control: no-cache");
header("Pragma: no-cache");

?>

However IE usually ignores this (especially when the content is CSS or JS).

apokryfos
  • 38,771
  • 9
  • 70
  • 114