Javascript XDomainRequest在IE中的应用;新鲜的;仅在第一次调用中使用数据

Javascript XDomainRequest在IE中的应用;新鲜的;仅在第一次调用中使用数据,javascript,json,internet-explorer,refresh,xdomainrequest,Javascript,Json,Internet Explorer,Refresh,Xdomainrequest,我正在使用一个JSON请求来检索我正在开发的网页中的一些流量表信息。为了与IE兼容,我使用XDomainRequest。XDR在第一次加载页面期间成功检索数据,但后续调用(加载后在页面上使用windows.setInterval)不会返回更新的信息。清除浏览器缓存也不会起任何作用。页面加载新数据的唯一方法是重新启动IE并加载页面。我错过了什么 这是我的XDR代码: //Now Access & Process the NWS Gage Data if ($

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

            });
        }
谢谢!
Steve

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

例如:

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

我尝试了您的建议,但在本例中,它使XDR请求返回一个“无法识别的关键字”错误,并且没有返回数据。需要明确的是,这不是Chrome或Firefox(使用jQueryJSON请求选项)中的问题。通常时间戳不应该是问题。对不起,我帮不了你。也许唯一的解决方案是创建一个代理服务,它将请求转发到真正的web服务。在对代理服务的请求中,可以传递timestamp参数。此外,您不必为IE使用变通方法,因为您不再需要使用跨域ajax请求。虽然USGS服务器不会接受您建议的附加参数,但它确实有一个有效的启动时间参数。最后,我用历元中的当前日期/时间减去3小时,然后将其作为开始日期/时间。现在我的URL总是唯一的,因此在IE中返回非缓存信息。再次感谢!