I am throwing entity object to javascript by ajax
in php
// obtaining object by doctrine2
$lesson = $em->getRepository('Lesson')
->findOneBy(array('id' => $myId));
// $lesson->getName(); // I can access the entity property here like this.
//throwing object as json
$response = array("responseCode" => 200,'lesson' => $lesson,"success" => true);
return new Response(json_encode($response),200,array('Content-Type'=>'application/json'));
in javascript
function reloadItems(){
var url= "http://myajax.com/ajax/";
$.post(url,something,function(data){
// I got lesson object from php as json here.
// however these doesn't work
// console.log(data.lesson.name);
// console.log(data.lesson.getName);
});
How can I get the each repository data in javascript??