0

I have a web page that reads an xml file using ajax. Ajax because I only want to update the numbers not the entire page. It reads the file every 5 Seconds using SetInterval(), because the file is updated every 5 Seconds. I would like to know how many times the xml file has reloaded, by adding a Counter into the querystring. I fail at this, because the page reloads if I change the querystring. Is it possible to do this in JavaScript/JQuery?

This is how I tried to solve this:

function loadXMLDoc(filename) {
var xmlhttp;

if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest();
}
else // code for IE5 and IE6
{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

var href = window.location.href;

if (counter < 1) {
    href += "index.html?count=" + ++counter;
    window.location.href = href;
} else {
    href = href.substring(0, href.length - 1);
    window.location.href = href + ++counter;
}

xmlhttp.open("GET", filename + "?count=" + counter, false);
xmlhttp.send();

var xdoc = xmlhttp.responseXML;

var xmlDoc = new ActiveXObject('Msxml2.DOMDocument.6.0');
xmlDoc.loadXML(new XMLSerializer().serializeToString(xdoc));

return xmlDoc;

also this does not produce the querystring I want either:

http://localhost:52646/index.html?count=1index.html?count=1

Is this possible to acheive?

Terje Solem
  • 656
  • 6
  • 21

1 Answers1

0

you might use HTML5 localstorage to achieve this, below is some code for your ref:

if(localStorage.getItem('count')=='undefined')
    localStorage.setItem('count',1);
else
    localStorage.setItem('count',parseInt(localStorage.getItem('count'))++);
theinvisible
  • 148
  • 11