title: Flask how to redirect to new page after ajax call
body: <p>I try to redirect to a new page after ajax post but I have not been successfull yet.</p>
  
  <p>My template looks like this:</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
   $(function() {
  
       var selectedForm = 0;
  
       function doWork() {
           var response = $('#reply1').val();
           console.log(response);
           $.post({url: "receiver", data: JSON.stringify({selectedForm: selectedForm, response : response}),
                   contentType: "application/json", success: function(){}});
       }
  
       $('.respondButton').click(function(e) {
           e.preventDefault();
           var selectedButton = $(this).attr('id');
           selectedForm = selectedButton.replace('response', '');
           console.log(selectedForm);
       });
  
       $('#submitButton1').click(function(e) {
           e.preventDefault();
           doWork();
       });
  
   });
  &lt;/script&gt;
  </code></pre>
  
  <p>Html part:</p>
  
  <pre><code>&lt;a id="response1" href="" class="respondButton"&gt;
      &lt;span&gt;response1&lt;/span&gt;
  &lt;/a&gt;
  
  &lt;a id="response2" href="" class="respondButton"&gt;
      &lt;span&gt;response2&lt;/span&gt;
  &lt;/a&gt;
  
  &lt;form  action="/receiver" method="post" id="form1" name="form1"&gt;
      &lt;textarea type="text"  rows ="3" name="reply1" id="reply1"&gt;&lt;/textarea&gt;
      &lt;button type="submit"  name="submitButton1" id="submitButton1"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>And on the server side flask application looks like this:</p>
  
  <pre><code>#!flask/bin/python
  
  import sys
  
  from flask import Flask, render_template, request, redirect, Response, url_for
  import random, json
  
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  @app.route('/somepage')
  def somepage():
      return 'Success'
  
  
  @app.route('/receiver', methods = ['POST'])
  def worker():
  
      data = request.get_json()
      result = ''
      result = str(data)
  
      print(result)
  
      return (redirect(url_for('somepage')))
  
  
  if __name__ == '__main__':
  
      app.run(debug=True)
  </code></pre>
  
  <p>When I open Chrome developer tools and click network it looks fine and I may see success message but stil browser doesn't redirects to <code>/somepage</code></p>