我目前正在開發一個基於symfony2的項目,其中包含大量的ajax用法。如何在symfony2中接收JSON
現在我想通過$.ajax();
(POST類型)發送JSON並在symfony2控制器中處理它。 但我不太清楚我如何訪問控制器內的JSON。
現在我已經得到了以下內容:
JS:
$.ajax({
url: url,
type:"POST",
data:json,
success:function (data) {
$('div.tooltip p').html(data);
}
});
而且PHP:
public function registrationAction(Request $request) {
if($request->getMethod() == 'POST') {
// How to receive??
}
return $this->render('KnowHowERegistrationBackendBundle:Create:registration.html.twig');
}
我不知道的唯一的事情是我如何可以訪問JSON? 我相信這很容易,我只是沒有看到它。 感謝您的幫助!
你應該看看FOSRestBundle:https://github.com/FriendsOfSymfony/FOSRestBundle – igorw 2012-03-15 22:14:39