jquery脚本请求不缓存
我正在尝试缓存一个非常简单的 JavaScript 响应。我正在使用rails,我的views/projects/index.js.erb仅包含以下内容:
alert('hi');
当我请求时,
$.ajax({
type: 'GET',
cache: true,
url : '/projects',
dataType: 'script'
});
我收到弹出窗口“hi”,并且我在服务器日志中看到对Projects#index操作作为js的请求已被做到了。
然后,在不刷新浏览器的情况下,我再次执行此操作,
$.ajax({
type: 'GET',
cache: true,
url : '/projects',
dataType: 'script'
});
我看到服务器仍然收到请求 谁能发现我可能错过的任何东西吗?
谢谢你!
I am trying to cache a very simple javascript response. I am using rails and my views/projects/index.js.erb contains only the following:
alert('hi');
and when I request
$.ajax({
type: 'GET',
cache: true,
url : '/projects',
dataType: 'script'
});
I get the popup 'hi' and I see in my server log that a request to Projects#index action as js has been made to it.
Then without refreshing the browser and I do it again
$.ajax({
type: 'GET',
cache: true,
url : '/projects',
dataType: 'script'
});
I see that the server still gets a request
can anyone spot anything that I might have missed?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现出了什么问题。 jQuery 实际上用 包围传入的脚本,以便浏览器评估传入的代码。但缓存机制只是将代码保存为文本,当重新请求时,它会以文本形式返回代码,但不会对其进行评估。因此,需要明确地评估代码
I found out what's wrong. jQuery actually surround the incoming script with a so that the browser evaluates the incoming code. But the caching mechansim merely saves the code as text and when one re-request, it returns the code as text but not evaluate it. Therefore, one needs to eval the code explicitly