• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

64
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

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


        });
almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda