【发布时间】:2013-07-28 08:07:02
【问题描述】:
我想将一个数组从 Jquery 传递给 PHP。
我的 jquery:
var jsonFormat = JSON.stringify(myArray);
$.post("myPHPFile.php", jsonFormat).done(function(data) {
$('.foo').append(data);
});
我在浏览器控制台中按预期看到了 myArray
我的 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;
}
?>
在浏览器控制台中,我得到状态 200 ok,但没有响应。我期待将数组视为响应。
【问题讨论】:
-
试试
print_r($_POST)看看贴出来的参数,其实jsonFormat可能没有你想的参数