Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda