在Chrome阿贾克斯+ pushState错误 [英] Ajax + pushState bug in Chrome
问题描述
我遇到一个奇怪的bug在Chrome 19。我实现了一个完整的AJAX网站(每一个非外部链接是通过AJAX请求开通)用pushState支持。我通过JSON格式发送Ajax中的HTML片段。
I've encountered a strange bug in Chrome 19. I implemented a full-AJAX website (every non-external link is opened via AJAX request) with pushState support. I transmit the HTML snippets in AJAX via JSON format.
当我通过一个外部链接离开我的网站,然后回去,浏览器呈现缓存数据,该网址 - 而不是全网页的问题是,他缓存JSON内容,并表明,
When I leave my site via an external link and then go back, Chrome renders cached data for that URL - the problem is, he caches the JSON content and shows that, instead of full web-page.
这是可重复这些步骤(更新:我删除了AJAX功能在我的网站自那以后,所以这个bug确实不再出现):
This is reproducible by these steps (UPDATE: I removed AJAX functionality on my website since then, so this bug does no longer appear):
- 开启 http://beta.mirtes.cz/
- 点击第二数据链(16 6. 2012旁边的这一切都始于一个陌生的邮件)。此页面(你现在在的http://测试版。 mirtes.cz/it-all-began-with-a-strange-e-mail )通过AJAX加载。
- 点击这一切都始于一个奇怪的电子邮件。您将被重定向到一个外部网站。
- 点击后退,在Chrome浏览器后页面完全加载。
- Open http://beta.mirtes.cz/
- Click on the second date link (16. 6. 2012 next to "It all began with a strange e-mail"). This page (you are now at http://beta.mirtes.cz/it-all-began-with-a-strange-e-mail) is loaded via AJAX.
- Click on "It all began with a strange e-mail". You are redirected to an external website.
- Click "Back" in Chrome after the page is completely loaded.
我尝试发送所有AJAX响应与缓存控制:无缓存,但没有效果。
I try to send all AJAX responses with Cache-Control: no-cache, but with no effect.
火狐12工程确定。
推荐答案
我想出了一个解决办法 - 我执行AJAX请求额外的虚拟GET参数 - ?AJAX = 1。通过这种方式,浏览器可以识别通常的HTML内容和JSON之间的差异。它不会对用户的任何影响,参数仅在萤火虫
I came with a workaround - I perform AJAX request with additional dummy GET parameter - ?ajax=1. This way the browser can recognize the difference between usual HTML content and JSON. It doesn't have any impact on the user, the parameter is visible only in Firebug.
这篇关于在Chrome阿贾克斯+ pushState错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!