Webbrowser is not showing the updated version of a txt file but opening a new browser shows correct file

后端 未结 1 1738
既然无缘
既然无缘 2020-12-11 12:58

I\'m experimenting with PHP together with Ajax and JQuery to make a site where I can write to a text file and then have the site load the textfile\'s contents into a div.

相关标签:
1条回答
  • 2020-12-11 13:46

    Append a time string to the title of the file in the load statement to prevent caching -

    $(document).ready(function() {
        setInterval(function() {
            var ms = (new Date).getTime(); // epoch time
            $("#text").load("storydoc.txt?ms=" + ms ); // add query string
        }, 2000);
    });
    

    The added string is inconsequential to the actual file but will have the affect of making the request 'new' each time because the added time string will be different and there will not be a copy in the cache.

    0 讨论(0)
提交回复
热议问题