0
我想用$ .post()从cakePHP控制器中检索一个json数组。我想我不需要一个视图文件,因为我会将autorender设置为false,并且我正在寻找一个json数组。当我使用$ .ajax和$ .get,但使用$ .post时,我设法得到一个响应,我得到一个400错误的请求。
我的代码:
$.post("controller/action",{id: "1"}, function(data) {
console.log(data);
});
public function action() {
$this->autoRender = false;
$array = $_POST;
header("Content-type: application/json");
echo json_encode($array);
exit;
}
如何可能做得更好任何帮助或建议吗?正如前面提到的$ .get,$ .ajax确实可行,但数据回调不会返回任何内容(但萤火虫显示响应数组)。
这可能只是你的问题中的一个错字,但'$ .post'应该用')'关闭,我当然不是CakePHP专家 - 但我确定'exit()'shouldn不在那里 – ManseUK 2012-04-17 09:38:06