[英]XDomainRequest in IE- “fresh” data only in first call
我正在使用JSON請求來檢索正在開發的網頁中的一些流規信息。 為了實現IE兼容性,我使用XDomainRequest。 XDR在頁面的第一次加載期間成功檢索了數據,但隨后的調用(加載后我在頁面上使用windows.setInterval)不會返回更新的信息。 清除瀏覽器緩存也無濟於事。 頁面加載新數據的唯一方法是實際重新啟動IE並加載頁面。 我想念什么?
這是我的XDR代碼:
//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);
});
});
}
謝謝! 史蒂夫
如果要確保您不會從ajax調用中獲取緩存的信息,則可以在URL后面附加一個時間戳。
例如:
$.getJSON("http://example.com?param1=asdf&_=" + new Date().getTime());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.