I am sending form data with jQuery $ .post () to the bulb function. The function performs some lengthy data calculations. In this case, I do not want to send the HTML code, but instead render a new template. How to do this when I call a function using jQuery / AJAX?
The form:
<form id='myform'> <input type='text'> some input... <input type='button' value='send form' id='mybutton'> </form>
Computing the input of the form takes some time, so I submit it using jQuery:
$.("#mybutton").click(function() { // get the data in form $exampledata = 'foo' $.post("/some/flask/function", {'data': $exampledata}, function(response) { can I render a new template here with data from flask function? }); });
In the bulb, the corresponding function looks like this:
@app.route('/some/flask/function', methods=['POST']) def longCalculation(): form = request.form data = form['data'] result = runTheLongCalculation(data) this does not work --> return render_template('result.html',r=result) how can I render a new template after an jQuery/AJAX call?
I don't want to send back the redirect URL and JSON, but actually create a template.
source share