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?

1

1 Answer 1

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'))++);
Sign up to request clarification or add additional context in comments.

Comments

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.