1

I am using this code for reading files. Everything is OK with Chrome and FF, but IE does not update the data from the file ... seems to be reading from cache??? Any suggestions? Thanks

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","YOUR_FILE.txt",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseText;
1
  • 1
    How does jQuery fit in here? Commented Apr 6, 2013 at 22:22

2 Answers 2

3

You could try adding a dynamic string argument to the end of the filename to prevent caching.

Try this:

var time = new Date().getTime();
xmlhttp.open("GET", "YOUR_FILE.txt?time=" + time, false);

Check out Javascript's Date.getTime() documentation.

Sign up to request clarification or add additional context in comments.

Comments

0

Please see http://msdn.microsoft.com/en-us/library/ms537505(v=vs.85).aspx
Microsoft suggests slightly different code:

var xmlHttp = null;
if (window.XMLHttpRequest) {
  // If IE7, Mozilla, Safari, and so on: Use native object.
  xmlHttp = new XMLHttpRequest();
}
else
{
  if (window.ActiveXObject) {
     // ...otherwise, use the ActiveX control for IE5.x and IE6.
     xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.