我正在尝试将 javascript 对象从视图传递到 Zend 中的更新控制器。
我的 JSON 字符串如下所示:
[{"item_id":null,"parent_id":"none","depth":0,"left":"1","right":4},{"item_id":"1","parent_id":null,"depth":1,"left":2,"right":3}]
并将其分配给 variable jsonObj
。
我的 AJAX 帖子看起来像:
$.ajax({
type: "POST",
url: "http://dev.jp-websolutions.co.uk/cms_nishan/admin/navigation/update",
data: jsonObj,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function(data) {
alert(JSON.stringify(data, null, 4));
},
error: function() {
alert("failure");
}
});
return false;
}
;
我的更新控制器是:
public function updateAction() {
if ($this->getRequest()->isXmlHttpRequest()) {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
}
$data = $this->_request->getPost();
$result = Zend_Json::decode($data);
print_r($result);
}
但我不能让它工作,如果我使用
$result = Zend_Json::decode([{"item_id":null,"parent_id":"none","depth":0,"left":"1","right":4},{"item_id":"1","parent_id":null,"depth":1,"left":2,"right":3}]);
它正确显示,如
Array (
[0] => Array (
[item_id] =>
[parent_id] => none
[depth] => 0
[left] => 1
[right] => 4 )
[1] => Array ( [item_id] => 1 [parent_id] => [depth] => 1 [left] => 2 [right] => 3 ) )
我怎样才能得到这份工作?任何帮助都感激不尽 :)