Internet Explorer Caching asp.netmvc ajax results

前端 未结 7 873
故里飘歌
故里飘歌 2020-12-16 13:09

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 co

相关标签:
7条回答
  • 2020-12-16 13:22

    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.

    0 讨论(0)
  • 2020-12-16 13:27

    If you are using the Ajax Helper, you can set the AllowCache parameter to false like this:

    @Ajax.ActionLink("AjaxCall", "AjaxMethod", "DeconflictedFiles",
                     new { }, 
                     new AjaxOptions
                     {
                         AllowCache = false,
                     }) 
    

    And IE won't cache the results of the call.

    0 讨论(0)
  • 2020-12-16 13:32

    actually in IE browser caching not clear automatically. but in chrome scripts working accepted.so you need to try for clearing data in browser level.

    0 讨论(0)
  • 2020-12-16 13:35

    I also found this very useful on a similar (but not identical) issue.

    http://forums.asp.net/t/1681358.aspx/1?Disable+cache+in+Ajax+ActionLink+extension+method+in+asp+net+MVC

    Basically make sure that you're using POST as opposed to GET in your requests. Doing so seems to prevent IE from caching.

    Eg:

    @Ajax.ActionLink("Clear Contacts", MVC.Home.ClearContacts(), new AjaxOptions{HttpMethod = "POST", UpdateTargetId="targetDiv"})

    0 讨论(0)
  • 2020-12-16 13:36

    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();
    
    0 讨论(0)
  • 2020-12-16 13:36

    You can use HttpMethod = "POST" on your AjaxOptions

    var ajaxOpts = new AjaxOptions { UpdateTargetId = "TargetDiv",  HttpMethod = "POST"};
    

    like this exp;

    @Ajax.ActionLink("Text","ActionName", new AjaxOptions { UpdateTargetId = "TargetDiv",  HttpMethod = "POST"})
    
    0 讨论(0)
提交回复
热议问题