Prevent browser caching of AJAX call result

后端 未结 21 1276
醉酒成梦
醉酒成梦 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:13

    As @Athasach said, according to the jQuery docs, $.ajaxSetup({cache:false}) will not work for other than GET and HEAD requests.

    You are better off sending back a Cache-Control: no-cache header from your server anyway. It provides a cleaner separation of concerns.

    Of course, this would not work for service urls that you do not belong to your project. In that case, you might consider proxying the third party service from server code rather than calling it from client code.

提交回复
热议问题