Jquery.get()在IE8/9中不起作用。韩元';t加载未修改的缓存页304 代码点火器版本“2.0.3” jquery1.7 Jquery历史插件
我有一个CodeIgniter应用程序,它是以ajax方式构建的。我的职能如下:Jquery.get()在IE8/9中不起作用。韩元';t加载未修改的缓存页304 代码点火器版本“2.0.3” jquery1.7 Jquery历史插件,jquery,ajax,caching,internet-explorer-8,http-status-code-304,Jquery,Ajax,Caching,Internet Explorer 8,Http Status Code 304,我有一个CodeIgniter应用程序,它是以ajax方式构建的。我的职能如下: $(document).on('click','.ajax_link',function(e){ //Stop the normal href action e.preventDefault(); //Grab the destination URL var new_url = $(this).attr('href') //Grab the content via
$(document).on('click','.ajax_link',function(e){
//Stop the normal href action
e.preventDefault();
//Grab the destination URL
var new_url = $(this).attr('href')
//Grab the content via ajax and pass it to the history change function
$.get(base_url+new_url,function(data){
History.pushState({
content:data.content,
url:data.url
}, data.title, data.url);
//Refresh some site variables
refresh();
},'json');
});
它所做的一切都是通过一类ajax_链接捕获对锚元素的点击,并将响应发送给一个函数,该函数负责将响应数据放置到页面中
这在Chrome和FF中工作。我单击链接,jQuery发出get请求,我得到一个JSON对象和我的历史记录。pushState()函数将一些JSON数据注入我的页面
我遇到的问题是IE8。基本上,当我第一次打开应用程序时,链接起作用,但它们只起作用一次。第二次单击链接时:
- ajax
GET
- 接收304的响应(未修改)
- 不调用
回调函数,因此停止jQuery.get()
$.ajaxSetup ({cache: false});
IE(和Opera)不喜欢“application/json”,在这里我们必须将响应呈现为“text/plain”。更改这一行:
var new_url = $(this).attr('href')
为此:
var new_url = $(this).attr('href') + '?' + Math.random();
这称为“CacheBuster”,有效地创建了一个类似以下内容的url:
"website.com/page.html?1241233"
每次点击“.ajax\u link”时,随机数都会有所不同,因此IE会认为这是一个新页面,并正确获取它。谢谢您的建议。通过在document.ready函数中放置以下内容,我成功地解决了这个问题:$.ajaxSetup({cache:false});谢谢你的回答,很抱歉我花了这么长时间才接受。这确实是我需要的解决方案。另请参见: