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

117
Views
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 answers
Answer question

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 Report
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!