This is my routes.py
@app.route('/test', methods=['POST', 'GET'])
def test():
# form = BrandChoice()
# email = request.form['email']
# name = request.form['name']
choice = request.form['choice']
print(choice)
q = session.query(Brand.brand).filter(Brand.pid == choice)
print(q)
return jsonify({'choice': q })
And this is my test.js file
$(document).ready(function() {
$('form').on('submit', function(event) {
$.ajax({
data : {
name : $('#nameInput').val(),
email : $('#emailInput').val(),
choice : $('#brandInput').val()
},
type : 'POST',
url : '/test'
})
.done(function(data) {
if (data.error) {
$('#errorAlert').text(data.error).show();
$('#successAlert').hide();
}
else {
$('#errorAlert').text(data.choice).show();
$('#successAlert').text(data.name).show();
// $('#errorAlert').hide();
}
});
event.preventDefault();
});
});
I don't quite get why is it that I cannot get the query result to show up. If I were to replace my 'q' with name for example, it works as intended.
How do I go about returning my query result so that I can display it in my errorAlert?