开发者

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:

  1. Make your server written return a unique string each and every time it is called
  2. Check if this string exists in your javascript temp variables
  3. If yes, its stale, if no, its new.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜