302使用AJAX发布请求进行重定向:
问题描述:
我正在为Web应用程序实现注销功能.我有一个函数,当用户单击退出"按钮时会调用该函数.
I'm implementing logout functionality for a web application. I have a function, which is called when the user clicks the sign out button.
$.post(window.location.pathname + '/logout');
注销服务仅适用于帖子.
The logout service works only with post.
会发生什么:
- 按预期的位置返回状态: http://myapp.com/logout.html
- 显然,jquery ajax调用只是从那里接起的,并立即向该位置发出GET请求.
- GET请求返回正确的html,但返回的是AJAX样式,浏览器未加载重定向页面
我想发生的事情是:
- 按预期的位置返回状态: http://myapp.com/logout.html
- 浏览器重定向到给定位置
答
如果您不想使用Ajax处理响应,则不要使用Ajax.
If you don't want to handle the response using Ajax, then don't use Ajax.
<form action="/logout" method="post">
<input type="submit" value="logout">
</form>