0
所以,我和Ajax POST谁打电话在retunrn这样的JSON响应的一个功能:学说收集JSON响应问题
$images = $this->getEntityManager()->getRepository('AppBundle:Image')->findBy(array(),array(),5);
$response = new JsonResponse();
$response->setData(array(
'images' => $images
));
return $response;
我得到的五行,但都是空的.. 。像下面的图像中:
例如,i。从元件i中的数组返回一些属性和它的工作原理:
$images = $this->getEntityManager()->getRepository('AppBundle:Image')->findBy(array(),array(),5);
$response = new JsonResponse();
$response->setData(array(
'images' => $images[0]->getSlug()
));
return $response;
这是简单的Ajax代码:
$.ajax({
method: 'POST',
url: $("#scroll-down").attr("data-href"),
success: function(response) {
console.log(response);
},
error: function() {
console.log(response);
}
}).fail(function() {
console.log(response);
});
权,学说ArrayColelction拥有一个私人属性,叫做$ elemnts。解决方案可以使用适当的库来序列化对象,如jms_serializer。这个库使用反射,然后私有方法将被序列化! – erlangb