问题
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:
- The 302 status is returned as expected with Location: http://myapp.com/logout.html
- Apparently the jquery ajax call just picks up from there and immediately makes a GET request to said location.
- 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:
- The 302 status is returned as expected with Location: http://myapp.com/logout.html
- 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