I have this code:
$("#sendData").click(function(e) {
// converts to JSON the array and returns a st开发者_C百科ring.
var updateValues = JSON.stringify(dataArray);
$.post("test.php", updateValues, function(data){
document.write(alert)});
});
As you may see, is my intention to send a JSON array to test.php. Now in test.php i have something like:
<?php
if(isset($_POST["updateValues"])) {
echo $_POST["updateValues"];
} else {
echo "Error."
}
?>
Now, i'm getting "Error". I believe it's because the array can not be passed just that way, even if it's JSON-ed. What's the correct way of passing arrays to PHP scripts?
Try...
$.post("test.php", {'updateValues': updateValues}, function(data){
alert(data);
});
You had a few syntax issues - and each post variable should have a key in the object to access it in PHP like that.
精彩评论