![](/img/trans.png)
[英]How do i make my navigation bar centered without affecting the javascript for mobile version
[英]How do I achieve navigation without affecting browser history?
如果你在这里 go: http://twitter.com/account/resend_password
然后在不填写表格的情况下单击“发送说明”,它似乎正在执行一个完整的非 ajax 请求。
但是,如果我查看浏览器历史记录,前一页 (resend_password) 不在历史记录中。 就好像它发出了 ajax 请求。
twitter 在做什么? 这真的只是一个 ajax 请求,还是在做一些棘手的事情?
window.location.replace
将加载一个页面,但不会将其保存在历史记录中。
window.location.replace('http://twitter.com/account/resend_password');
这不是 ajax 请求。
这也不是什么棘手的事情。
Twitter is only answering the HTTP POST request with an HTTP response code number 302 (Moved Temporarily) - see http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection . 浏览器回答好像它是一个 HTTP 响应代码号 303(请参阅其他)。
事实上,所发生的只是重定向到同一页面。
编辑:添加代码用于测试目的。
我刚刚用下面的代码进行了测试,它证实了上面所说的:
<form method="post"><input type="submit" value="click here" /></form>
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
header( 'Location: /test.php', true, 302 );
?>
我使用 PHP 作为服务器端语言。 我将此脚本作为test.php
保存在网络服务器公共根文件夹中。 它的行为与 Twitter 页面完全相同:单击表单提交按钮,使用header
function 触发302 重定向。 浏览器历史不会改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.