User Tools

Site Tools


tech:ajax-cache

There are several way to resolve AJAX Cache Issue:

  1. In server side, we can add this one:
    header(“Cache-Control: no-cache, must-revalidate”);
  2. When sending AJAX request, we can add: anyAjaxObj.setRequestHeader(“If-Modified-Since”,“0”);
  3. When sending AJAX request, we can add: anyAjaxObj.setRequestHeader(“Cache-Control”,“no-cache”);
  4. Add new parameter after URL, for example: “?fresh=” + Math.random(); or “?timestamp=” + new Date().getTime();
  5. Use “post” instead of “get”. It is not recommended.

===

For jquery:

$.ajax( cache: false, url: 'http://myurl', data: {} );

This will work for this particular request. If you want to expand the scope of this setting to all AJAX requests, you can set it on the global AJAX configuration:

$.ajaxSetup({ cache: false });

tech/ajax-cache.txt · Last modified: 2018/07/24 08:13 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: 沪ICP备12046235号-2
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki