我想返回我的ajax请求呈现的视图和一些整数值,但我不知道该怎么做。我尝试将包含内容的数组编码为 json,但随后在成功回调函数中,我获得了一个数组,我可以看到带有整数的字段,以及空的"header"参数。那么如何在 Symfony2 中返回整数参数和渲染响应呢?
我从你的问题中假设你想返回类似的东西。
array(
'html' => **your html**,
'integer' => **your integer**,
);
如果这是正确的,您可以执行以下操作...
// ->renderResponse render the string and creates a response object for you to return
// ->render just renders the string into a variable
$html = $this->container->get('templating')->render(**template**, **parameters**);
$integer = **your integer**;
// Return a JSON object with the correct headers and what not
return new JsonResponse::create(array(
'html' => $html,
'integer' => $integer,
));