简体   繁体   English

强制IE在加载时重新下载文本文件

[英]Force IE to re-download text file on load

My JavaScript has an function that goes off onload that takes a .txt file and creates an array from it. 我的JavaScript有一个函数,它关闭onload ,它接受.txt文件并从中创建一个数组。 The page works fine in Chrome, but doesn't update in IE -- IE seems to cache the .txt file and re-create the array from the cache, ignoring any updates made to the .txt. 该页面在Chrome中工作正常,但在IE中不更新 - IE似乎缓存.txt文件并从缓存中重新创建数组,忽略对.txt所做的任何更新。 Is there any way to force IE to re-download the .txt before creating the array so that the user isn't working with an outdated version of the information? 有没有办法强制IE在创建数组之前重新下载.txt,以便用户不使用过时的信息版本?

edit: Code!! 编辑:代码!! (changed the file pathname, all else is the same) (更改了文件路径名,其他所有内容都相同)

function createArray() {
    var txtFile = new XMLHttpRequest();
    txtFile.open("GET", "http://PATHNAME/names.txt", true);
    txtFile.onreadystatechange = function() {
        if (txtFile.readyState === 4) {
            if (txtFile.status === 200 || txtFile.status === 0) {
                nameArray = txtFile.responseText.split("\n");
            }
        }
    };
    txtFile.send(null);
}

Furthermore, the file is stored on the server, in the same folder as the page that the data displays on, which is one level above the JavaScripts folder. 此外,该文件存储在服务器上,与显示数据的页面位于同一文件夹中,该文件位于JavaScripts文件夹上方一级。 So the directories look like: 所以目录看起来像:

page.html
names.txt
SCRIPTS FOLDER
    array.js

获取请求缓存,强制它通过更改URL来获取新文件。

txtFile.open("GET", "http://PATHNAME/names.txt?ts=" + new Date().getTime(), true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM