Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net mvc and jquery $.ajax on IE9

I have a ajax call to a controller that is supposed to send me an updated view back so that I can update my page with the updated data. But I get 304: Not Modified header back.

I tried a to use the no-cache option for the ajax call, and tried to manually add a timestamp to the end of request url as well, non of them worked on IE9.

This works perfectly on chrome without setting the caching option.

I am not too sure where the problem is.

The following is the code I used, which I thought worked after manually adding the timestamp. QA said it doesn't work on her computer.

     $.ajax({
         url: form[0].action + "?cc="+new Date().getTime(),
         type: 'POST',
         cache: false,
         data: $(form).serialize()
     })
    .success(createFilterCleanup);
like image 803
y62wang Avatar asked Feb 29 '12 20:02

y62wang


1 Answers

Try setting the following in your JQuery $.ajax, to prevent IE from caching your ajax requests. This has always worked for me.

$.ajaxSetup({ cache: false });

OR

$.ajax({ type: 'POST', cache: false }); 

http://api.jquery.com/jQuery.ajax/

"If set to false, it will force requested pages not to be cached by the browser. Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL. "

Below is an article with some other possible solutions: http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/

Hopefully this helps.

like image 185
Nickz Avatar answered Sep 18 '22 22:09

Nickz