I am using symfony3:
I am calling a method via ajax call:
Controller
/**
* @Route("personnel/domainlist/{id}", name="ajax_method")
* @Method("GET")
*/
public function domainlist(Request $request,$id){
$repository = $this->getDoctrine()->getRepository('AppBundle:ENTITYNAME');
$res=$repository->findBy(array('COLNAME' => $id));
// create a JSON-response with a 200 status code
$response = new Response(json_encode($res));
$response->headers->set('Content-Type', 'application/json');
return $response;
die;
}
form above code i am getting following result: print_r($res);
Array
(
[0] => AppBundle\Entity\ENTITYNAME Object
(
[domain_id:AppBundle\Entity\ENTITYNAME:private] => 15
[domain_title:protected] => ABC
[domain_group_id:protected] => 1
)
)
AJax code:
$.ajax({
url: "domainlist/" + pdoamin_id,
type: 'POST',
dataType: 'json',
success: function(result) {
alert(result);
}
});
});
Anyone can help me how can i return json to ajax method in symfony3