ビューから Zend の更新コントローラーに JavaScript オブジェクトを渡そうとしています。
私の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 ) )
どうすればこの仕事を手に入れることができますか?どんな助けでも大歓迎です:)