How to disable Ajax caching?

后端 未结 3 1809
夕颜
夕颜 2020-12-06 06:43

I am having an issue with ajax caching, This was a problem in IE browser too but i fixed it by Writing the Following code.

    response.setHeader(\"Cache-Co         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 06:58

    According to RFC 2616 section 9.5 about POST

       Responses to this method are not cacheable, unless the response
       includes appropriate Cache-Control or Expires header fields. However,
       the 303 (See Other) response can be used to direct the user agent to
       retrieve a cacheable resource.
    

    So, the browser must not cache POST responses, unless the response specifies otherwise. In the same time, browsers may cache GET responses, unless the response specifies otherwise. So, for the requests that should not be cached, such as AJAX requests, POST is preferrable method.

    If you, for any reason, don't want to use POSTs for AJAX, you should use the trick mentioned by minitech, it is in fact widely used to force browser to load current version of any resource.

提交回复
热议问题