3

我正在为 Web 应用程序实现注销功能。我有一个函数,当用户单击退出按钮时会调用该函数。

$.post(window.location.pathname + '/logout');

注销服务仅适用于 post。

会发生什么:

  1. 302 状态按预期返回 Location: http://myapp.com/logout.html
  2. 显然,jquery ajax 调用只是从那里接起并立即向所述位置发出 GET 请求。
  3. GET 请求返回正确的 html,但是它返回的是 AJAX 样式,重定向页面没有被浏览器加载

我想要发生的是:

  1. 302 状态按预期返回 Location: http://myapp.com/logout.html
  2. 浏览器重定向到给定位置
4

1 回答 1

5

如果您不想使用 Ajax 处理响应,请不要使用 Ajax。

<form action="/logout" method="post">
    <input type="submit" value="logout">
</form>
于 2013-07-25T14:51:55.220 回答