302使用AJAX发布请求进行重定向: [英] 302 Redirection with AJAX post request:
本文介绍了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.
会发生什么:
- 按预期的位置返回<302>状态: http://myapp.com/logout.html
- 显然,jquery ajax调用只是从那里接起的,并立即向该位置发出GET请求.
- GET请求返回正确的html,但返回的是AJAX样式,浏览器未加载重定向页面
我想发生的事情是:
- 按预期的位置返回<302>状态: 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>
这篇关于302使用AJAX发布请求进行重定向:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文