Passing variables from Flask back to Ajax
<p>When I access my page root, my flask generates a base jinja template which contains elements: </p>

<pre><code>&lt;div&gt;&lt;span id="var_1"&gt;{{ var1|safe }}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span id="var_2"&gt;{{ var2|safe }}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span id="var_3"&gt;{{ var3|safe }}&lt;/span&gt;&lt;/div&gt;
</code></pre>

<p>In this template I have dropdown menus which using Ajax POSTS their values and then I retrieve them from flask to do some calculations. </p>

<pre><code>function submitValues(val) {
    var entry1 = $('#dropdown1').val(); 
    $.ajax({
    type: "POST",
    url: "/getData",
    data: {entry2_id: val, entry1_id: entry1},
    success: function(data){
    }
    });
}
</code></pre>

<p>Once I'm done with the calculations, how can I pass the variables back to ajax to update the 3 elements in the base template with the new 'calculated' variables?</p>

<p>In flask:</p>

<pre><code>@app.route("/getData", methods=['POST'])
def getData():
    entry2Value = request.form['entry2_id']
    entry1Value = request.form['entry1_id']

    #### DO CALCULATIONS HERE WHICH GENERATES 3 NEW VALUES
    #### newVal1, newVal2, newVal3
    #### change var1, var2, var3 from the original template to these new vals
    return ??
</code></pre>

<p>I have tried to recall the base template with the new values within the ajax called flask function but this doesn't update the html. The values are obtained from ajax into the function just fine but my issues is how to 're-submit' these values into the base template or even, re-render the template from scratch. </p>

<p>Can I call the 'calculation' flask function by a get() in the ajax 'success' like so:</p>

<pre><code>function submitValues(val) {
    var entry1 = $('#dropdown1').val(); 
    $.ajax({
    type: "POST",
    url: "/getData",
    data: {entry2_id: val, entry1_id: entry1},
    success: function(data){
        $.get("/getData", function(newvar1, newvar2, newvar3)){
        }
    }
    });
}
</code></pre>

<p>and then replace the element by id with the new variables?</p>

<p>Thanks!</p>