y62wang
y62wang

Reputation: 568

.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);

Upvotes: 6

Views: 1119

Answers (2)

Nickz
Nickz

Reputation: 1880

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.

Upvotes: 4

STO
STO

Reputation: 10638

Using POST method instead of GET or pass random dummy parameter (like current timestamp) is only robust method to prevent caching in IE. :(

EDITED: Had read carefully and found appending timestamp not helping you - please give a small code sample to show how do you append it.

Upvotes: 0

Related Questions