Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer Caching asp.netmvc ajax results

I'm having an issue with a page in internet explorer. I have an ajax call that calls a form, in other browser, when I click the link it passes in the controller and load correctly data. but in IE, when its loaded once, it aways brings me the same old results without passing in the controller.

like image 405
Diego Correa Avatar asked Apr 16 '10 13:04

Diego Correa


2 Answers

Try:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

This attribute, placed in controller class, disables caching. Since I don't need caching in my application, I placed it in my BaseController class:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public abstract class BaseController : Controller
{

Here is nice description about OutputCacheAttribute: Improving Performance with Output Caching

You can place it on action too.

like image 116
LukLed Avatar answered Sep 21 '22 16:09

LukLed


You could try setting the cache option to false:

$.ajax({
    url: '/controller/action',
    type: 'GET',
    cache: false,
    success: function(result) {

    }
});

This option will force the browser not to cache the request.


UPDATE:

Based on the comment you could add a unique timestamp to the url to avoid caching issues:

var d = new Date();
var myURL = 'http://myserver/controller/action?d=' + 
    d.getDate() + 
    d.getHours() + 
    d.getMinutes() + 
    d.getMilliseconds();
like image 43
Darin Dimitrov Avatar answered Sep 23 '22 16:09

Darin Dimitrov