Prevent browser caching of AJAX call result

后端 未结 21 1316
醉酒成梦
醉酒成梦 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 05:16

    If you are using IE 9, then you need to use the following in front of your controller class definition:

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

    public class TestController : Controller

    This will prevent the browser from caching.

    Details on this link: http://dougwilsonsa.wordpress.com/2011/04/29/disabling-ie9-ajax-response-caching-asp-net-mvc-3-jquery/

    Actually this solved my issue.

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

    Of course "cache-breaking" techniques will get the job done, but this would not happen in the first place if the server indicated to the client that the response should not be cached. In some cases it is beneficial to cache responses, some times not. Let the server decide the correct lifetime of the data. You may want to change it later. Much easier to do from the server than from many different places in your UI code.

    Of course this doesn't help if you have no control over the server.

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

    What about using a POST request instead of a GET...? (Which you should anyway...)

    0 讨论(0)
提交回复
热议问题