Jquery.get()不工作在IE8 / 9。将不会加载缓存的页面304不修改 [英] Jquery.get() not working in IE8/9. Won't load cached pages 304 not modified

查看:257
本文介绍了Jquery.get()不工作在IE8 / 9。将不会加载缓存的页面304不修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code点火器版本2.0.3 jQuery的1.7 jQuery的历史插件

大家好,

我有一个codeIgniter应用程序,我已经建立在Ajax的方式。我有一个函数如下:

  $(文件)。在('点击','。ajax_link',功能(五){
    //停止正常HREF行动
    即preventDefault();

    //取得目标网址
    VAR new_url = $(本).attr(HREF)

    //取得通过AJAX的内容并把它传递到历史变化的函数
    $获得(BASE_URL + new_url,功能(数据){
        History.pushState({
            内容:data.content,
            网址:data.url
        },data.title,data.url);
        //刷新一些网站的变量
        刷新();
    },'JSON');
});
 

所做的只是抓住锚元素的点击一类ajax_link和发送响应处理安置的响应数据插入到页面的功能。

该作品在Chrome和FF。我点击链接,jQuery让GET请求,我得到一个JSON对象,我history.pushState()函数注入一些JSON数据到我的网页。

我的问题是在IE8。从本质上讲,当我第一次打开应用程序,环节的工作,但他们只能使用一次发生了什么是。第二次我点击一个链接:

  • 是否AJAX GET
  • 接收的响应304(未修改)
  • 在不调用 jQuery.get()的回调函数,因此停了下来。

如果我清除缓存它的工作原理了。因此,我的假设是,IE是做get请求,但后来它看到它已经要求在过去完全相同的文件...等完全停止进程。

是否有人知道一个解决这个吗?我有一个寻提到的304错误和错误使用Ajax和缓存中的IE浏览器,但还没有发现一个问题等同于我的,只是还没有。

pciated任何帮助非常AP $ P $

(测试在Windows虚拟机IE8,和IE 8模式在Internet Explorer 9)

解决

只是需要添加以下code到我的document.ready功能,这个问题就消失了。

  $ ajaxSetup({缓存:假})。
 

解决方案

更​​改此行:

  VAR new_url = $(本).attr(HREF)
 

要这样:

  VAR new_url = $(本).attr(HREF')+'? +的Math.random();
 

这被称为CACHEBUSTER,并有效地创建类似于网址:

 website.com/page.html?1241233
 

这是随机数将是.ajax_link的每一次点击都会不同所以IE认为它是一个新的页面,并妥善得到它。

Code Igniter version '2.0.3' Jquery 1.7 Jquery History plugin

Hi guys,

I have a CodeIgniter app that I've built in an ajax fashion. I have a function as follows:

$(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');
});

All it does it captures clicks on anchor elements with a class of ajax_link and sends the response to a function that handles the placement of that response data into the page.

This works in Chrome and FF. I click the link, jQuery makes the get request, I get back a JSON object and my history.pushState() function injects some of the json data into my page.

The problem I have is in IE8. Essentially what's happening is when I first open the app, the links work but they only work once. The second time I click a link it:

  • Does the ajax GET
  • Receives a response of 304 (Not Modified)
  • Doesn't call the jQuery.get() callback function and therefore stops dead.

If I clear the cache it works again. So my assumption is that IE is doing the get request, but then it sees that it's already requested that exact same file in the past... and so stops the process entirely.

Does anybody know of a solution to this? I have had a look for mentions of 304 errors and errors with ajax and caching in IE but have not found a problem identical to mine just yet.

Any help much appreciated

(Tested on Windows Virtual Machine IE8, and IE 8 Mode in Internet Explorer 9)

Solved

Just needed to add the following code to my document.ready function and the issue disappeared.

$.ajaxSetup ({cache: false});

解决方案

Change this line:

var new_url = $(this).attr('href')

To this:

var new_url = $(this).attr('href') + '?' + Math.random();

This is called a "CacheBuster" and effectively creates a url similar to:

"website.com/page.html?1241233"

That random number will be different for every click of ".ajax_link" so IE will think its a new page and get it properly.

这篇关于Jquery.get()不工作在IE8 / 9。将不会加载缓存的页面304不修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆