302 Redirection with AJAX post request:

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

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

    <form action="/logout" method="post">
        <input type="submit" value="logout">
    </form>
    
    链接地址: http://www.djcxy.com/p/45420.html

    上一篇: 区分来自经过认证的API响应的公共API响应

    下一篇: 使用AJAX发布请求重定向302: