1

I've run into an issue with a simple javascript code, which is pretty much just a copy of the code here: http://www.w3schools.com/xml/xml_to_html.asp

<html>
<head>

<script type="text/javascript">
function displayMain()
{
  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","catalog.xml",false);
  xmlhttp.send();
  xmlDoc=xmlhttp.responseXML; 

  x=xmlDoc.getElementsByTagName("VAR");
  i=0;

  variable1=(x[i].getElementsByTagName("VARIABLE")[0].childNodes[0].nodeValue);
  name1=(x[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
  value1=(x[i].getElementsByTagName("VALUE")[0].childNodes[0].nodeValue);
  txt="Variable: " + variable1 + "<br />Name: " + name1 + "<br />Value: "+ value1;
  document.getElementById("mainDiv").innerHTML=txt;
}

</script>
</head>
<body onload="displayMain(); setInterval('displayMain()', 1000)">

<div id='mainDiv'></div>

</body>
</html>

All I want to do is change the xml file and thus have the new value updated on the page. So for instance I change the value in the xml file it will reflect in the html page. It works great on Firefox and Chrome, but not on IExplorer. IE just keeps my old value in there, even when I refresh the page. The only way I can get it to update is by deleting the temp. files and history. Does anyone know a way around this? It dosn't seem very practical for a user to have to all that.

1 Answer 1

2

GET requests are cached. Set no cache headers on the server.

or

Append a random query string parameter

xmlhttp.open("GET","catalog.xml?qs=" + new Date().getTime(),false);
Sign up to request clarification or add additional context in comments.

2 Comments

I think I have the server set so no it's not cached, I still need to look into it. On appending the parameter I get a syntax error, missing a ) after argument. Though it does look correct to me.
Found the error, needed a '+' xmlhttp.open("GET","catalog.xml?qs=" + new Date().getTime(),false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.