Prevent browser caching of AJAX call result

后端 未结 21 1200
醉酒成梦
醉酒成梦 2020-11-22 04:47

It looks like if I load dynamic content using $.get(), the result is cached in browser.

Adding some random string in QueryString seems to solve this iss

相关标签:
21条回答
  • 2020-11-22 04:52

    If you are using .net ASP MVC, disable the caching on the controller action by adding the following attribute on the end point function:

    [OutputCacheAttribute(VaryByParam = "*", Duration = 0, NoStore = true)]
    
    0 讨论(0)
  • 2020-11-22 04:53

    add header

    headers: {
                    'Cache-Control':'no-cache'
                }
    
    0 讨论(0)
  • 2020-11-22 04:55

    The following will prevent all future AJAX requests from being cached, regardless of which jQuery method you use ($.get, $.ajax, etc.)

    $.ajaxSetup({ cache: false });
    
    0 讨论(0)
  • 2020-11-22 04:58

    append Math.random() to the request url

    0 讨论(0)
  • 2020-11-22 04:59

    Basically just add cache:false; in the ajax where you think the content will change as the progress go on. And the place where the content wont change there u can omit this. In this way u will get the new response every time

    0 讨论(0)
  • 2020-11-22 05:01

    Following the documentation: http://api.jquery.com/jquery.ajax/

    you can use the cache property with:

    $.ajax({
        method: "GET",
        url: "/Home/AddProduct?",
        data: { param1: value1, param2: value2},
        cache: false,
        success: function (result) {
            // TODO
        }
    });
    
    0 讨论(0)
提交回复
热议问题