I am trying to get data from webpage to my flask app and after a few operations on it,the output list im trying to send it back to front end as a dropdown list.
What i have done till now:
there is a user form where the user enters details and clicks on submit and he gets a json output.
in this form,I have a search button which when the user inputs a string,that string is sent to the flask app route and few search operations are done and outputs a list of items(TILL this part it is working!)
What i need to get to work is the output list should again be sent back to the form page which i have trouble getting it to work.
This is what i have done so far:
var successFunction = function(response) {
/* do something here */
$('#info').html(JSON.stringify(data, null, ' '));
});
}
$(function(){
$('#btnSignUp').click(function(){
$.ajax({
url: '/signUp',
data: $('form').serialize(),
type: 'POST',
success: successfunction(response)
error: function(error){
console.log(error);
}
});
});
});
the flask app has something like this:
from flask import Flask, render_template, request,jsonify,url_for
import json,os,re
app = Flask(__name__)
@app.route('/',methods=['GET','POST'])
def form():
if request.method == 'POST': #this block is only entered when the form is submitted
result = { key: value[0] if len(value) == 1 else value
for key, value in request.form.iterlists()
}
return json.dumps(result,indent=2)
return render_template('form_backup1.html')
@app.route("/signUp", methods=["POST","GET"])
def signUp():
jsdata = request.form['Nitro']
<couple of find and search operations the output of which is in
this dropdown_list list>
return jsonify(dropdown_list)
if __name__ == '__main__':
app.run(host="0.0.0.0",port="5000",debug = True)
snipped html page just to show the search box:
<div id='nitroo'>
Nitro_search: <input type="text" placeholder="Apply Nitro" name="Nitro" id="Nitro">
<button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="button">Search</button>
<pre id="info"></pre>
As I said I am able to get the text entered by the user in the html form when he clicks on search.
the output lists from python is where I am having trouble of getting to front end.
Any help on this would be much appreciated.
Thanks
See Question&Answers more detail:
os