Reputation: 97
I'm using a JSON request to retrieve some stream gage information in a web page I'm developing. For IE compatibility, I am using XDomainRequest. The XDR successfully retrieves data during the first load of the page but subsequent calls (I use windows.setInterval on the page after load) do not return updated information. Clearing the browser cache does nothing, either. The only way the page will load new data is to actually restart IE and load the page. What am I missing??
Here's my XDR code:
//Now Access & Process the NWS Gage Data
if ($.browser.msie && window.XDomainRequest) {
//Internet Explorer Doesn't support JQuery's getJSON so you must use an alternative method
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("get", "http://waterservices.usgs.gov/nwis/iv/?format=json&sites=12150800,12167000,12161000,12150400,12138160,12134500,12186000,12155300,12155500¶meterCd=00065");
xdr.onload = function () {
//parse response as JSON
var JSON = $.parseJSON(xdr.responseText);
if (JSON == null || typeof (JSON) == 'undefined')
{
JSON = $.parseJSON(data.firstChild.textContent);
}
array.forEach(JSON.value.timeSeries, function(curGage, i){
curGageID = curGage.sourceInfo.siteCode[0].value;
curGageName = curGage.sourceInfo.siteName;
curGageHeight = curGage.values[0].value[0].value;
curGageObs = curGage.values[0].value[0].dateTime;
//Another Internet Explorer quirk. Date format must be changed due to IE's different interpretation
curGageObs = curGageObs.replace(/\-/g,"/");
curGageObs = curGageObs.replace(/T/g," ");
curGageObs = curGageObs.substring(0,curGageObs.length-10);
var theDate = new Date(curGageObs);
document.getElementById('u' + curGageID + 'Height').innerHTML = curGageHeight + " Feet";
document.getElementById('u' + curGageID + 'Date').innerHTML = theDate.toString('M/d/yyyy @ h:mm tt');
assignNwsStageColor(curGageID, curGageHeight);
});
};
xdr.send();
} else {
$.getJSON("http://waterservices.usgs.gov/nwis/iv/?format=json&sites=12150800,12167000,12161000,12150400,12138160,12134500,12186000,12155300,12155500¶meterCd=00065", function(data) {
array.forEach(data.value.timeSeries, function(curGage, i){
curGageID = curGage.sourceInfo.siteCode[0].value;
curGageName = curGage.sourceInfo.siteName;
curGageHeight = curGage.values[0].value[0].value;
curGageObs = curGage.values[0].value[0].dateTime;
var theDate = new Date(curGageObs);
document.getElementById('u' + curGageID + 'Height').innerHTML = curGageHeight + " Feet";
document.getElementById('u' + curGageID + 'Date').innerHTML = theDate.toString('M/d/yyyy @ h:mm tt');
assignNwsStageColor(curGageID, curGageHeight);
});
});
}
Thanks! Steve
Upvotes: 0
Views: 157
Reputation: 534
If you want to ensure that you don't get cached information from an ajax call, you could append a timestamp to the url.
For example:
$.getJSON("http://example.com?param1=asdf&_=" + new Date().getTime());
Upvotes: 1