简体   繁体   English

IE中的XDomainRequest-仅在首次调用时才“刷新”数据

[英]XDomainRequest in IE- “fresh” data only in first call

I'm using a JSON request to retrieve some stream gage information in a web page I'm developing. 我正在使用JSON请求来检索正在开发的网页中的一些流规信息。 For IE compatibility, I am using XDomainRequest. 为了实现IE兼容性,我使用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. XDR在页面的第一次加载期间成功检索了数据,但随后的调用(加载后我在页面上使用windows.setInterval)不会返回更新的信息。 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. 页面加载新数据的唯一方法是实际重新启动IE并加载页面。 What am I missing?? 我想念什么?

Here's my XDR code: 这是我的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);                    
                  });                

            });
        }

Thanks! 谢谢! Steve 史蒂夫

If you want to ensure that you don't get cached information from an ajax call, you could append a timestamp to the url. 如果要确保您不会从ajax调用中获取缓存的信息,则可以在URL后面附加一个时间戳。

For example: 例如:

$.getJSON("http://example.com?param1=asdf&_=" + new Date().getTime()); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM