Internet Explorer Caching asp.netmvc ajax results

柔情痞子 提交于 2020-01-28 05:33:25

问题


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.


回答1:


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.




回答2:


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



回答3:


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"})



回答4:


I've blogged about fixing the IE cache issue for both jQuery and the MS client library:

http://yoavniran.wordpress.com/2010/04/27/ie-caching-ajax-results-how-to-fix/

Hope this helps!




回答5:


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"})




回答6:


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.




回答7:


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.



来源:https://stackoverflow.com/questions/2653092/internet-explorer-caching-asp-netmvc-ajax-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!