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

111
Vistas
JQuery won't fire an action from modal

I have the following form in a Bootstrap modal window

            <form id="formCsv" class="row gy-2" enctype="multipart/form-data">
              <div class="col-md-5 ">
                <input class="form-control" type="file" id="file" name="file">    
              </div>
                <div class="col-md-3">
                <button type="submit" id="csvBtn"class="btn btn-primary" name="something"> Upload </button>
              </div>
              <div id="loading" class="clearfix col-md-2">
                <div class="spinner-border text-primary float-right" role="status"></div>
              </div>
              <div class="col-md-2">
                <button type="button" id="export-btn" class="btn btn-primary" disabled>Export CSV</button>
              </div>
            </form>

JQuery file

console.log("Works");

$(document).ready( function() {
    // Submit form data via Ajax
    $("#formCsv").on('submit', function(e)
    {
        alert("test");
        e.preventDefault();
        var form_data = new FormData($(this)[0]); 

        $.ajax({
            type: 'POST',
            url: 'src/positionen/getCsvData.php',
            data: form_data,
            contentType: false,
            cache: false,
            processData:false,
            success: function(response)
            {
                console.log(response);
                var json = JSON.parse(response);                
                addToTable(json);
            },
        });
    });
});

The console.log() works. The alert() within is not triggered and no errors are thrown.

Any ideas why it is like this?

Without the form in a modal it just works fine.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I see the problem.

The form is loaded later into the DOM you need to change your listener to $(document).on('submit', '#formCsv', function() {//your code})

That way Jquery will also listen to content that is added later by an ajax call.

about 4 years ago · Juan Pablo Isaza Denunciar
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