“重新打开上次关闭的标签"导致显示最后一个ajax请求内容 [英] "Re open last closed tab" causing to show last ajax request content

查看:24
本文介绍了“重新打开上次关闭的标签"导致显示最后一个ajax请求内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 HTML 5 历史 API 来保存 ajax 请求发生时的状态,如果用户请求到同一页面而没有 ajax 请求,我会提供完整的 html 内容.

I am using HTML 5 history api to save state when ajax requests happen and i provide full html content if user request to same page with none ajax request.

浏览器的重新打开上次关闭的选项卡"功能将上次的ajax请求内容带到服务器上.如果浏览器在不带上最后一个请求内容的情况下进行请求,那么一切都会正常工作.但是浏览器只显示最后的ajax请求内容.

"Re-open last closed tab" feature of browser brings last ajax request content without hitting to server. If browser would request without bring last request content then everything would work without problem. But browser just show last ajax request content.

我在 Chrome 17、Firefox 10 上遇到过这种情况.(我没有在 ie9 上尝试过,因为它没有支持历史记录 api)

I have been experienced this on Chrome 17, Firefox 10. (i haven't tried it on ie9 because it has no support history api)

这个问题的众所周知的解决方案是什么?

What is well-known solution for this problem ?

这些ajax请求只是对服务器的获取"请求.

These ajax requests are just "get" request to server.

由于几个原因,真的不可能在 jsfiddle.net 中演示它.您可以在您的本地主机中进行演示,如下所示.

it is really not possible to demonstrate it in jsfiddle.net because few reasons. You can demonstrate it in your localhost like below.

向服务器发出get"请求并拉取 json 对象,然后将该 url 推送到历史 API 中,如下所示.

Make "get" request to server and pull json objects then push that url into history api like below.

history.pushState(null,null,url);

然后关闭该选项卡并单击浏览器的重新打开上次关闭的选项卡"功能.你看到了什么 ?Json 响应体?浏览器显示它而不向服务器发出请求,对吗?

Then close that tab and click "Re-open last closed tab" feature of your browser. What do you see ? Json response body ? Browser shows it without making request to server, right ?

推荐答案

问题是由 http 响应标头引起的.标头包含 ajax 请求的可缓存信息,因此浏览器会显示缓存中的 url 内容,而不会命中数据库.

Problem was causing by http response headers. Headers was contain cacheable information for ajax requests so browser was showing that url content from cache without hit to database.

从响应头中删除缓存参数后,浏览器能够访问服务器而无需从缓存中获取内容.

After removing cache params from response headers then browser was able to hit server without brings content from cache.

这篇关于“重新打开上次关闭的标签"导致显示最后一个ajax请求内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆