gpt4 book ai didi

javascript - IE- "fresh"中的 XDomainRequest 数据仅在第一次调用中

转载 作者:行者123 更新时间:2023-12-03 11:53:00 24 4
gpt4 key购买 nike

我正在使用 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&parameterCd=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&parameterCd=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()); 

关于javascript - IE- "fresh"中的 XDomainRequest 数据仅在第一次调用中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25727852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com