[ad_1]
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
[ad_2]