i am noticing a error when im trying to return json from a fetchAll.
in the controller i have a fetchAction
$result = $model->fetchAll();
echo Zend_Json::encode($result);
exit();
in a .js file i have a ajax call:
$.ajax({
type: "GET",
url: "/module/index/fetch",
dataType: "json",
processData: false,
success: function(data) {
console.log(data);
$.each(data, function(index, obj){
// console.log(obj);
});
}
});
if i do a print_r($result); i get:
Array
(
[0] => Module_Model_Module Object
(
[_message:protected] => test
[_created:protected] => 1332188757
[_dependent_table:protected] =>
)
[1] => Module_Model_Module Object
(
[_message:protected] => 123123
[_created:protected] => 1332194812
[_dependent_table:protected] =>
)
)
but the console.log(data); returns 2 empty json objects: [{},{}].
any ideas why i get the json empty back??
my guess is that Zend_Json is not able to transform the Module_Model_Module objects into arrays and then into JSON, you could try to call toArray to the objects and see if then Zend_Json can properly encode them