title: Flask session not persisting value set by ajax if there is no return statement
body: <p>I am new to web app and I am sorry if this question is totally out of line.</p>
  
  <p>I have a simple ajax call to set states of python flask app as below.</p>
  
  <p>Below is how I set the value</p>
  
  <p><strong>-- setting value --</strong></p>
  
  <p><strong>Javascript (page1.html)</strong></p>
  
  <pre><code>function foo(val1, val2){
     $.ajax({
           url: "./set_option",
           type: "POST",
           data: {arg1:val1, arg2:val2}
     });
  }
  </code></pre>
  
  <p><strong>python side</strong></p>
  
  <pre><code>@app.route('/set_option', methods=['post'])
  def set_option():
      session['val1'] = request.form.get('arg1')
      session['val2'] = request.form.get('arg2')
  </code></pre>
  
  <p>below is how I tried to do something with the value</p>
  
  <p><strong>-- retrieving value --</strong></p>
  
  <p><strong>Javascript (page2.html)</strong></p>
  
  <pre><code>function do_something_with_store_value(){
      $.ajax({
             url:"./print_them",
             type: "POST"
      });
  }
  </code></pre>
  
  <p><strong>python side</strong></p>
  
  <pre><code>@app.route('/print_them', methods=['post'])
  def print_them():
      print(session['val1'])
      print(session['val2'])
  </code></pre>
  
  <p>In above example, I see <strong>session['val1']</strong> and <strong>session['val2']</strong> do not exist in <strong>def print_them()</strong>.  However, if I modify <strong>function foo(val1, val2)</strong> to handle return response and <strong>def set_option()</strong> to return a simple string value <strong>session['val1']</strong> and <strong>session['val2']</strong> are maintained.  </p>
  
  <p>I am very confused about this behavior.  I guess I can just use the modification to make it work, but I am really hesitant to do what I do not understand clearly.</p>
  
  <p>Do I have to have return response from flask/python server for session value saving between requests?  I thought I could use ajax post call to set state in server side without expecting any data back from the server.  </p>
  
  <p>Do I still have to return some sort of success/failure notification to ajax call?  what does it have to do with session not keeping the value?</p>
  
  <p>Can somebody please shed some light in this confusion?</p>
  
  <p>Thanks!</p>