title: Using JQuery/AJAX to call a function and use it's value in a Flask template
body: <p>I have a flask app and want to update a value in a template periodically. This value will come from a Flask route. For example my views are defined like so:</p>
  
  <pre><code>from . import main
  from flask import render_template
  
  
  @main.route('/')
  def index():
      return render_template('index.html')
  
  
  @main.route('/price')
  def price():
      return 5
  </code></pre>
  
  <p>Now my index.html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;p id="p1"&gt;Replace this text&lt;/p&gt;
  
  &lt;script&gt;
    setInterval(function(){
      document.getElementById("p1").innerHTML = "some value";
    }, 5000);
  &lt;/script&gt;
  
  &lt;p&gt;The paragraph above was changed by a script.&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>How can I call the <code>/price</code> route from within the js and then use the returned value in <code>id=p1</code>?</p>