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

118
Vistas
Problems passing js data to php page using ajax jquery

Hi everyone

After one week searching what could be the problem I have not discovered what could fix it.
I already have done some jquery ajax calls before and I am currently trying to realize a Wordpress pluging.

There I am trying to pass an array in Javascript using Ajax Jquery to a Php page using POST request. Ajax request is correctly achieved ( success and done events are triggered ) but when I am accessing the page $_POST is empty. I even tried in the code below to simply put simple string data but I can't access it in php page.

This is my Jquery code :

$('#Enregistrer').click(function(){
    saveArray= new Array();
    var i=0;
    $('.q1').each(function(){
        if ($(this).hasClass('tablesorter-filter-row')==true){
            // doing nothing
        }
        else{
            saveArray[i]=new Array();
            for (var j=0; j<6; j++){
                if ($(this).children().eq(j).hasClass('m1') || $(this).children().eq(j).hasClass('m2')){
                    var value = $(this).children().eq(j).children('select').val();
                }
                
                else{
                var value = $(this).children().eq(j).html();
                }
                saveArray[i][j]= value;
            }
        i++;
        }
    });
    console.log(saveArray);
    var data = 'test';
    $.ajax({
        url:'../api/send_form.php',
        method:'POST',
        data: { 'data': data },
       
        success: function(resp){
            console.log('ok');
            window.location='../api/send_form.php'; 
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
        }


    });
});

If you need more details don't hesitate, this is my first post on stackoverflow.I try to be as precise as possible.
Thanks

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

0

maybe your attempt is missing the type: 'POST', also added a few more elements

$.ajax({
            dataType: 'html', 
            type: 'POST',
            url:'../api/send_form.php',
            method:'POST',
            data: { data: data },
            processData: false,
            contentType: false,
            success: function(resp){
                console.log('ok');
                window.location='../api/send_form.php'; 
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }


        });
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