Ajax 和浏览器缓存问题
我有一个在 Sinatra 上运行的小型网站,它根据 xhr 请求通过 ajax 更新内容。
code
function get_shows() {
$.ajax({
type: 'GET',
dataType: 'HTML',
url: '/update/',
success: function(data) {
$('#show_list').fadeOut('fast', function(){
$(this).html(data).fadeIn('fast');
});
},
error:function(data){console.log(data.statusText)}
});
}
/
get '/update/' do
if request.xhr?
erb :index_show_list, :layout => false
else
erb :index
end
end
我遇到的问题是,当用户通过 ajax 更新内容时,该页面的浏览器缓存会更新,并且仅显示获取的代码片段,以及所有 head
和 body< > 标签消失了。页面会继续正常渲染,直到您离开页面,然后通过后退按钮返回,在这种情况下,显示的只是 html 片段,没有页面的其余部分。
I have small web site running on Sinatra which is updating content via ajax on a xhr request.
javascript
function get_shows() {
$.ajax({
type: 'GET',
dataType: 'HTML',
url: '/update/',
success: function(data) {
$('#show_list').fadeOut('fast', function(){
$(this).html(data).fadeIn('fast');
});
},
error:function(data){console.log(data.statusText)}
});
}
ruby
get '/update/' do
if request.xhr?
erb :index_show_list, :layout => false
else
erb :index
end
end
The issue I'm having is when a user updates content via ajax, the browser cache for that page updates and only shows the snippet fetched, and all the head
and body
tags are gone. The page continues to render ok, until you leave the page and then return via the back back button, in which case all that is displayed is the html snippet sans the rest of the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到过同样的问题。尝试在 ajax 请求中将缓存设置为 false。默认情况下它设置为 true。
有关详细信息,请参阅 http://api.jquery.com/jQuery.ajax/。
例子:
I've had this same issue. Try setting cache to false in your ajax request. By default it is set to true.
See http://api.jquery.com/jQuery.ajax/ for more info.
Example: