I want to pass an array from Jquery to PHP.
My jquery:
var jsonFormat = JSON.stringify(myArray);
$.post("myPHPFile.php", jsonFormat).done(function(data) {
$('.foo').append(data);
});
I see myArray in the browser console as expected
My PHP:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, DELETE, PUT, OPTIONS');
//echo json_decode(array('success' => 'yes'));
if ($_SERVER['REQUEST_METHOD']=="POST"){
$jsonFormat = $_POST['jsonFormat'];
echo $jsonFormat;
}
?>
In the browser console I get status 200 ok, but no response. I am expecting to see the array as a response.
print_r($_POST)and see the parameters that posted, actually there might be no parameter by thisjsonFormatas you expect