{% if products %}
<div class="products">
<form class="sendproduct" action="" method="POST">
please select a product: <select class="products_list" id="products_list" name="product_id">
{% for product in products %}
<option value="{{ product.id }}"><a href="{{ product.git_url[:-4] }}">{{ product.name }}</a></option>
{% endfor %}
</select>
</form>
</div>
{% endif %}
^^^^
||||
HTML CODE
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==--=-=-=-=-=-=--=-=-=-=-
$('#products_list').change(function() {
val = $( "#products_list option:selected" ).text();
$.ajax({
type: 'post',
url: '{{ url_for('main.add_version_list')}}',
data: $('.sendproduct').serialize(),
success: function (data) {
console.log(data)
}
});
});
^^^^
||||
AJAX CODE
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
product_id=3
^^^^
||||
raw data that is sent from jquery/ajax to the server acording to the firefox developer tools!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
@mod.route('add_version_list/', methods=['POST'])
def add_version_list():
product_id = request.form['product_id']
# products = Product.query.filter_by(product_id=product_id)
# global_product_name = products.name
return jasonify({"result":product_id })
# return jsonify({"result": render_template('main/add/versions_ajax.html')})
^^^^
||||
THE CODE PROCESSING THE FORM
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>
^^^^
||||
RESULT I GET FROM DEVELOPER TOOLS ON ERROR 400.