Prevent browser from caching AJAX requests

前端 未结 4 766
小鲜肉
小鲜肉 2020-12-08 04:52

I\'ve setup an app and it works fantastic on Opera and Firefox, but on Google Chrome it caches the AJAX request and will give stale data!

http://gapps.qk.com.au is t

4条回答
  •  盖世英雄少女心
    2020-12-08 05:27

    The browser cache behaves differently on different settings. You should not depend on user settings or the user's browser. It's possible to make the browser ignore headers also.

    There are two ways to prevent caching.

    --> Change AJAX request to POST. Browsers don't cache POST requests.

    --> Better Way & good way: add an additional parameter to your request with either the current time stamp or any other unique number.

    params = "action=" + action 
             + "&domain=" + encodeURIComponent(domain) 
             + "&preventCache="+new Date();
    

提交回复
热议问题