Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Flask and JavaScript -- requests

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')
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!