jQuery html response
Is it possible to determine if a response开发者_开发问答 returned by $.ajax was served from the browser's cache or was fresh?
Thanks.
No, that's not possible. What you can do is to create a new URL every time (eg: by appending a random string to the URL, which is ignored by the script on the server), or by setting the response's cache headers appropriately.
See: http://www.mnot.net/cache_docs/#CACHE-CONTROL
You might want to set max-age
, no-store
, no-cache
, must-revalidate
or a combination of the previous.
You can use the following in jQuery to make sure it does not cache:
$.ajaxSetup({cache: false}});
Am not sure what you are looking to achieve.
If you really want to know if the data is stale, you can do something like:
- Make your server written return a unique string each and every time it is called
- Check if this string exists in your javascript temp variables
- If yes, its stale, if no, its new.
精彩评论