最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - prevent xmlHttpReq 's browser caching - Stack Overflow

programmeradmin7浏览0评论

It seems that all the browsers other than Opera cache XHR requests in my Javascript program. The URL in the XHR request refers to a CGI program on the server which generates a different output everytime its called. B Is there a way in Javascript to make the browser not cache XHR requests?

It seems that all the browsers other than Opera cache XHR requests in my Javascript program. The URL in the XHR request refers to a CGI program on the server which generates a different output everytime its called. B Is there a way in Javascript to make the browser not cache XHR requests?

Share Improve this question asked Oct 21, 2010 at 6:47 GirishGirish 9253 gold badges10 silver badges20 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

For every AJAX request you make, generate a unique value and add it to the ajax URL as a query parameter:

/example/url/post.php?rand=09809807896768

I use to generate the current unix timestamp in JS and use that - this ensures I do not get duplicated stamps.

That way every request is unique and will not get cached. This is a simple but fairly mon AJAX trick - usually fixing IE and testing issues.

If you were to use jQuery, it does this for you by setting the property cache to false on the AJAX settings.

发布评论

评论列表(0)

  1. 暂无评论