title: How can search results be live and updated using Javascript accessing a Python application?
body: <p>I currently have a simple python application built on Flask and SQLAlchemy. The application is accesses a database <code>User</code> imported from another python file. The application has two views, one is <code>home</code></p>
  
  <pre><code>def home()
      if request.method == 'POST':
              search = Search(query=request.form['searchbox'], time=datetime.datetime.utcnow())
              db.session.add(search)
              db.session.commit()
  
              return redirect(url_for('results', query=request.form['searchbox']))
      return render_template('mainin.html')
  </code></pre>
  
  <p>which simply displays the index page and passes the data in the <code>searchbox</code> to the second view, <code>results</code> where they are displayed.</p>
  
  <pre><code>def results(query):
      results = User.query.filter(User.username.contains(query)).all()
      return render_template('results.html', results=results)
  </code></pre>
  
  <p>However, I instead want the results to be displayed on the same page as the searchbox, under where the user types their query. I think the effect I am going for is live results like when searching StackOverflow. I have done many searches, and I now realize that to achieve this effect I should just JQuery in the <code>mainin.html</code> page to make calls to the database as characters are entered into the search box. Currently, results are fetched by POST when the form's button is hit. So I assume that the JQuery needs to make a similar POST automatically, though I am not sure where to start. Many thanks in advance. </p>