I have a probably trivial question but I somehow can't make it work. Having the following JavaScript function, I would like to send the selectedRows variable to the flask function after clicking the button. When I do that, whatever gets to flask is "none". Any idea what am I missing? TIA!
The button HTML
<form action="{{ url_for('getSelectedFragments') }}" method='POST' >
<button id="subselected" class="btn btn-outline-primary btn-lg button-custom button-submit" type="submit" value="submit" href="{{ url_for('getSelectedFragments') }}">NEXT</button>
</form>
The JS function:
<script>
var $table = $('#table1');
function getRowSelections() {
return $.map($table.bootstrapTable('getSelections'), function(row) {
return row;
})
}
$('#subselected').click(function() {
var selectedRows = getRowSelections();
var selectedItems = '\n';
$.each(selectedRows, function(index, value) {
selectedItems += value + '\n';
});
var request = new XMLHttpRequest();
request.open('POST', '/getSelectedFragments', true);
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(selectedRows);
});
</script>
The Python code snippet:
@app.route('/getSelectedFragments', methods=['GET','POST'])
def getSelectedFragments():
if request.method == 'POST':
print(request.form.get('selectedRows'))
return render_template('index.html')