title: How to access a variable from an ajax/jquery POST rather than a GET
body: <p>This is probably a simple question but I cannot figure it out.</p>
  
  <p>If I have an update route like this:</p>
  
  <pre><code>@app.route('/update', methods=['GET', 'POST'])
  def update():
      x = request.args.get('foo')
      print(x)
      ...
  </code></pre>
  
  <p>and jquery like this:</p>
  
  <pre><code>$(document).ready(function(){
  
    $("#foobar").click(function() {
  
        $.ajax({
                url: '/update',
                type: "GET",
                data: { foo: 'hello stack exchange!'}
              });
    });
  
  });
  </code></pre>
  
  <p>I can access message and set it equal to x and then it prints out <code>hello stack exchange!</code></p>
  
  <p>but if I change the request to POST rather than GET how do I access it?</p>
  
  <pre><code>@app.route('/update', methods=['GET', 'POST'])
  def update():
      x = request['foo'] # THIS DOESN'T WORK
      print(x)
      ...
  </code></pre>
  
  <p>and jquery like this:</p>
  
  <pre><code>$(document).ready(function(){
  
    $("#foobar").click(function() {
  
        $.ajax({
                url: '/update',
                type: "POST",
                data: { foo: 'hello stack exchange!'}
              });
    });
  
  });
  </code></pre>
  
  <p>I understand the payload is not going through the URL so I need to change <code>request.args.get('foo')</code> to something else but if <code>request['foo']</code> doesn't work then what will?</p>