I am trying to pass a serialzed array via ajax request to my saveData.php file in order to save the data into my database.
var postData = $('#formular').serializeArray();
this is the Data I want to pass. I am creating an array with all the data in order to pass it as a json-Array to the php file:
var formArray={};
$.each(postData, function (index, field ){
formArray[field.name]=field.value;
});
var formData=JSON.stringify(formArray);
$.ajax({
type: 'POST',
contentType: 'application/json',
url:"functions/saveData.php",
data : formData,
}).done(function(data) {
console.log('done: '+data);
}).fail(function(data) {
console.log('fail: '+data);
});
When I look at the $_POST in PHP, there is an emty array ...
on the php side I try to catch the data with the following code....
$getPostedData=$_POST;
if($debug){
echo '<pre>';
print_r($getPostedData);
echo'</pre>';
}
This gives me the following Output:
Array
(
)
what am I doing wrong? Thanks for helping me out.