I'm trying to pass javascript objects from view to update controller in Zend.
My JSON string looks like :
[{"item_id":null,"parent_id":"none","depth":0,"left":"1","right":4},{"item_id":"1","parent_id":null,"depth":1,"left":2,"right":3}]
and it's assigned to variable jsonObj
.
My AJAX post looks like :
$.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;
}
;
And my update controller is :
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);
}
But I cant get it to work, if I use
$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}]);
It displays properly, as
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 ) )
How can I get this work? Any help will be much appreciated :)