2011-12-23 92 views
3

我有一个通过Jquery AJAX调用从XML文件抓取内容的页面。Internet Explorer在刷新时不会更新AJAX处理的内容?

问题是它将更新每个浏览器(除IE以外)刷新时XML文件的内容。

我试图与meta标签

<meta http-equiv="expires" content="-1"/> 
<meta http-equiv="cache-control" content="no-cache,must-revalidate" /> 
<meta http-equiv="pragma" content="no-cache"/> 

这是相关的JavaScript的一小部分

$(document).ready(function(){ 
$.ajax({type: "GET",url: "file1.xml",dataType: "xml", success: parseXml }); 
} 

function parseXml(xml){ 
document.getElementById(eventMonthName).innerHTML=firstxmlvari.getElementsByTagName('month')[0].childNodes[0].nodeValue; 
} 

任何建议将非常赞赏解决这个!

+0

我不知道是什么后端ŧ您使用的技术,但您应该尝试设置HTTP标头。根据我的经验,较旧的IE浏览器对元标签的反应并不好。这里是如何操作php中的http头。 http://www.jonasjohn.de/snippets/php/headers.htm – 2011-12-23 19:54:52

回答

3

是的,也许你遇到IE浏览器的缓存侵略性... 尝试设置HTTP头的事,但对于我的作品,正在添加当前时间的查询字符串这样的:

$(document).ready(function() { 
    $.ajax({ 
     type: "GET", 
     url: "/echo/xml/", 
     data: { 
      _rnd: new Date().getTime() 
     }, 
     dataType: "xml", 
     success: parseXml 
    }); 
}); 

function parseXml(xml) { 
    alert(xml); 
} 

的例如JSFIDDLE:http://jsfiddle.net/WVBDc/,检查传出的HTTP请求。

+0

哇!谢谢,这就是我一直在寻找的! – 2011-12-23 20:34:07

0

谢谢,我有一个类似的问题(只有在IE浏览器当然),并没有刷新请求后下拉。添加时间戳结合使用了这个技巧;

$(document).trigger("ready");

在成功的功能

,欢呼声!

4

您也可以使用“cache:false”选项,它的工作方式与Akos Lukacs提到的方式相同。结果是相同的,但您不必创建自己的日期。

$(document).ready(function() { 
    $.ajax({ 
     type: "GET", 
     url: "/echo/xml/", 
     cache: false, 
     dataType: "xml", 
     success: parseXml 
    }); 
}); 
3

在jQuery的.load方法不提供关闭缓存的一种便捷方式,我添加了一个时间戳参数,以我的要求,这是刚刚忽略在控制器级别:

$('#userDialog').load('/Users/Edit/' + someValue + '?timestamp=' + new Date().getTime(), function() { 
... 
}); 

或:

$('#userDialog').load('/Users/Create', { timestamp: new Date().getTime() }, function() { 
... 
}); 

这确实是只需要IE浏览器仍然是作为第10版

相关问题