title: Ajax POST request in Flask
body: <p>I'm trying to receive a POST request containing user-input form data using AJAX, but I keep returning errors. I'm following <a href="https://www.youtube.com/watch?v=IZWtHsM3Y5A" rel="nofollow noreferrer">this tutorial</a> almost verbatim.</p>
  
  <p>Here's my code:</p>
  
  <p>views.py</p>
  
  <pre><code>@app.route('/table_data', methods=['POST'])
  def table_data():
      user_id = request.form['userID']
      name = request.form['name']
      return user_id, name    #of course I'll return something more meaningful in the future
  </code></pre>
  
  <p>datapage.html</p>
  
  <pre><code>&lt;script type="text/javascript" src="app/static/js/submit.js"&gt;&lt;/script&gt;
  &lt;form action="{{ url_for('table_data') }}" class="form-inline" method="post"
          role="form" enctype="application/json"&gt;
      &lt;input type="text" class="form-control" id="userID" placeholder="4-Character ID"&gt;
      &lt;input type="text" class="form-control" id="name" placeholder="Name"&gt;
      &lt;button type='submit' class="btn btn-default"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>submit.js</p>
  
  <pre><code>$(document).ready(function() {
      $('form').on('submit', function(event) {
          $.ajax({
              data: {
                  userID: $('#userID').val(),
                  name: $('#name').val()
              },
              type: 'POST',
              url: '/table_data'
          })
      event.preventDefault();
      });
  });
  </code></pre>
  
  <p>My console is returning "GET /app/static/js/submit.js HTTP/1.1" 404", even though I know that the route to submit.js is correct.</p>
  
  <p>I'm brand new to JavaScript/jQuery. Any help for a rookie? </p>