302 Redirection with AJAX post request:

大憨熊 提交于 2021-02-05 06:16:05

问题


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.

What happens is:

  1. The 302 status is returned as expected with Location: http://myapp.com/logout.html
  2. Apparently the jquery ajax call just picks up from there and immediately makes a GET request to said location.
  3. The GET request returns the correct html, but it returns it AJAX style, the redirect page is not loaded by the browser

What I would like to happen is:

  1. The 302 status is returned as expected with Location: http://myapp.com/logout.html
  2. The browser redirects to the given location

回答1:


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>


来源:https://stackoverflow.com/questions/17861434/302-redirection-with-ajax-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!