[英]How to return both integer parameter and render template as response in Symfony2
我想返回我的Ajax請求呈現視圖和一些整數值,但是我不知道該怎么做。 我嘗試將具有內容的數組編碼為json,但是在成功的回調函數中,我得到了可以在其中看到帶有整數的字段的數組,並且“標頭”參數為空。 那么如何在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,
));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.