title: Posting data from html to flask view using jquery
body: <p>I have a dropdown that I am using. Here is the <strong>HTML</strong>:</p>
  
  <pre><code>  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
   &lt;script src="http://code.jquery.com/jquery-1.11.1.min.js"&gt;&lt;/script&gt;
    &lt;script src="{{url_for('static',filename='dropdown_change.js')}}"&gt;&lt;/script&gt;
  
  
   &lt;form action="{{url_for('select_ID')}}" method="POST"&gt;
    &lt;label for="input_ID"&gt;ID&lt;/label&gt;
    &lt;input type="text" /&gt;
    &lt;label for="Node_Type"&gt;Node_Type&lt;/label&gt;
    &lt;select id="dropdown_change"&gt;
      &lt;option value=1&gt;Customer&lt;/option&gt;
      &lt;option value=2&gt;Phone&lt;/option&gt;
      &lt;option value=3&gt;ID_Card&lt;/option&gt;
    &lt;/select&gt;
  &lt;input type='submit' value='Submit'&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my flask view:</p>
  
  <pre><code>import db_connect_test
  from db_connect_test import Viz_Connector
  from flask import Flask, request, session, redirect, url_for, render_template, flash,json,jsonify
  import os
  app = Flask(__name__)
  @app.route('/',methods = ['GET','POST'])
  def select_ID():
      if request.method == 'POST':
          ID=request.form['input_ID']
          Node_Type = request.form['Node_Type']
          data = Viz_Connector(ID,Node_type).get_data()
          return  render_template('dropdown.html',data=json.dumps(data))
  
  
      return render_template('dropdown.html')
  
  if __name__ == '__main__':
      host = os.getenv('IP','0.0.0.0')
      port = int(os.getenv('PORT',5000))
      app.secret_key = os.urandom(24)
      app.run(host=host,port=port)
  </code></pre>
  
  <p>Here is my jquery for the drop down. There is a event listenere for "clicking" of the submit button. I think the way I am hand</p>
  
  <pre><code>    $('input[type=submit]').click(function() {
     var ID = $("#input_ID").val();
     var selectID = $("#dropdown_change").val();
     $.ajax({
       type: "POST",
       url: "/select_ID",
  
       data: {
         ID: ID,
         Node_Type: selectID  //right way to pass the data to flask?
       },
       success: function(data) {
         alert('SUCCESS: ' + data);
       },
       error: function(xhr, textStatus, errorThrown) {
         document.getElementById('dropdown_change').selectedIndex = 0;
         showMsg('ERROR: ' + errorThrown);
         return false;
       }
     });
     return false;
   });
  </code></pre>
  
  <p>When I run this it fails with:</p>
  
  <pre><code>   400:Bad request
  </code></pre>