title: Logout request from Javascript to Flask
body: <p>I'm trying to logout user from my web application using Flask-Login.</p>
  <p>Here's my Javascript function:</p>
  <pre><code>function logout() {
    var req = new XMLHttpRequest();
    req.open(&quot;POST&quot;, &quot;http://myaddress/logout&quot;, true);
    req.withCredentials = true;
    req.send();
  </code></pre>
  <p>Here's my Python function:</p>
  <pre><code>@app.route('/logout')
  @login_required
  def logout_function():
      logout_user() # Built-in Flask-Login function
      return app.send_static_file('login.html')
  </code></pre>
  <p>When I send my request from Javascript I receive 200, but the page remains still, because redirect doesn't happen. I tried changing the last line of Python function to <code>return redirect(url_for('login_function'))</code>, but it didn't help.</p>
  <p>Could it be my Javascript function that causes the problem?</p>