title: ajax post data in flask view
body: <p>Here is my view function</p>
  
  <pre><code>@app.route('/share', methods=['GET', 'POST'])
  def share():
      form = ShareForm(request.form)
      if request.method == 'POST':
          title = form.title.data
          body = form.body.data
          share_id = form.share_id.data
          print 'form data %s %s %s' % (title, body, share_id)
          if not share_id:
              share = Shares(title, body, 'PUBLISHED', current_user.id)
              db.session.add(share)
              db.session.commit()
              form.share_id.data = share.id
          return jsonify({'status': 204, 'body': {'status': True}})
      else:
          return render_template('share.html', form=form)
  </code></pre>
  
  <p>The code for ajax post request</p>
  
  <pre><code>&lt;script&gt;
      $(function(){
        $('#share').on('click', function(e){
          e.preventDefault(); // preventing default click action
          $.ajax({
            url: '/share',
            type: 'post',
            contentType: "application/json; charset=utf-8",
            data: $('#share-form').serialize(),
            success: function(){
              console.log('success');
              console.log( $('#share-form').serialize());
            }, error: function(xhr, textStatus, errorThrown) {
              alert(xhr.responseText);
              console.log( $('#share-form').serialize());
            }});
          })
          //return false;
        });
  &lt;/script&gt;
  </code></pre>
  
  <p>in the view, when i try to print the request object, I get the following data</p>
  
  <pre><code>print request.data
  'title=adsl%3Blsaj%3Blj%3Bl&amp;body=j%3Bas%3Bl%3Bl+&amp;share_id='
  </code></pre>
  
  <p>But if I try to do,</p>
  
  <pre><code>print request.form.get('title', 'None')
  </code></pre>
  
  <p>I get 'None'</p>
  
  <p>Can somebody tell me how to fix this ?</p>