1

I have a small problem that I don't know how to deal with.

I've written some jQuery post/gets which work fine in FF, Opera and Chrome. But when run from explorer (any version) the updated content from the request does not get loaded into the browser. I've used developer tools and debugged the scripts, and the requests are sent with correct parameters. The actions are even executed, but it's not visible until I've cleared the browser history or open/close the browser.

This may be a silly question, but how do I get IE to recognize the changes from these requests?

5 Answers 5

15

Try setting the cache: false parameter to your AJAX requests as browsers might cache GET requests:

$.ajax({
    url: '/foo',
    type: 'GET',
    cache: false,
    success: function(result) {
        // TODO: update the DOM with the results
    }
});
3
  • I had same problem with IE. At one place, IE stripped out div tag from the HTML, which I was replacing on success of Ajax call. In another case, I was not able make the call because, while I assigned value to a variable, I did not write like this - var variablename = value.
    – KutePHP
    Apr 13, 2011 at 9:29
  • I think it works now! Looks like Cache: false did it's job. According to another post what it does is insert a timestamp so that IE recognizes the update. Nice one Apr 13, 2011 at 9:32
  • I've encountered similar issues. IE does tend to ignore you if you decide to turn off the cache completely. I haven't found a way to effectively shut off caching client side.
    – Flater
    Jul 12, 2012 at 11:55
2

What is happening is that you’re likely making a GET request to a web service for your AJAX call.

Internet Explorer, in its wisdom, will automatically cache responses from GET requests while other browsers will let you decide if you’d like to cache the result or not. Once IE has successfully made a GET request, it will no longer even make that AJAX call until the cache expires on that object. The solutions are:

Use POST: One option is to simply use POST requests instead of GET requests in your application. It’s usually a minor change to switch over from GET to POST on both the client and server side.

Response Headers:

You can also prevent caching by sending additional headers along with your response. By specifying the “Cache-Control” header with a value of “no-cache,no-store” and returning it with the web service response you can instruct the browser not to cache the result.

jQuery:

Finally, if you’re using jQuery, you can specify that you don’t want to cache the response from your AJAX requests either across the board using the $.ajaxSetup() method or on a per request basis as cache:false.

1

Try to add the following to the response header and the IE will not cache again:

response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");
response.addHeader("Cache-Control", "no-store");
response.addHeader("Cache-Control", "must-revalidate");
response.addHeader("Cache-Control", "Post-Check=0");
response.addHeader("Cache-Control", "Pre-Check=0");
response.addHeader("Expires", "Mon, 1 Jan 2006 05:00:00 GMT");//in the past

NOTE: the code is java code

1
  • At the server side and before you close the response it self; after you finish request processing (fetch the data or do what do you want to do) write the result in the response and add those parameters to the header of the response.
    – Saeed
    Apr 14, 2011 at 14:28
0

In IE using ajax call its create cache and store this old values.when you receive the response its put catch value.so you can make cache as false.

   $.ajaxSetup({ cache: false });

          OR 

   $.ajax({  url: your need url,
            cache: false,
            type: 'get',
            data:'your parameters',
            success: function(result) {
             //put your code here...
            }
  });

you can use both in your code.but first answer is best.

0
$.ajax({
        type: 'GET',
        cache: false,

this is works when writing cache: false, works in internet explorer with version 10 and 11 also in firefox and crome. Thank you stack overflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.