0

我正在使用 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);                    
                  });                

            });
        }

谢谢!史蒂夫

4

1 回答 1

1

如果要确保不会从 ajax 调用中获取缓存信息,可以在 url 中附加时间戳。

例如:

$.getJSON("http://example.com?param1=asdf&_=" + new Date().getTime()); 
于 2014-09-08T16:01:34.330 回答