JQuery.get () does not work in IE8 / 9. Do not load cached pages 304 not changed

Igniter version '2.0.3' code JQuery 1.7 JQuery History Plugin

Hi guys,

I have a CodeIgniter app that I created in ajax style. 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 he does is capture clicks on anchor elements with the ajax_link class and send a response to a function that handles the placement of this response data on the page.

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

I have a problem in IE8. Essentially, what happens when I first open the application, the links work, but they only work once. The second time I click the link:

  • Is there ajax GET
  • Gets a response of 304 (not changed)
  • Does not call the jQuery.get() callback function and therefore stops.

If I clear the cache, it works again. Therefore, I believe that IE is executing a get request, but then it sees that it has already requested the same file in the past ... and therefore completely stops the process.

Does anyone know about this solution? I searched for references to 304 errors and errors with ajax and caching in IE, but have not yet found a problem identical to mine.

Any help is much appreciated

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

solvable

I just need to add the following code to my document.ready function, and the problem disappeared.

 $.ajaxSetup ({cache: false}); 
+7
source share
2 answers

Change this line:

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

For this:

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

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

 "website.com/page.html?1241233" 

This random number will be different for each click of ".ajax_link", so IE will think about its new page and get it right.

+5
source

We have a problem with IE (and Opera), which does not like "application / json", where we should display the response as "text / plain".

0
source

All Articles