我正在尝试使用带有 VueJS-Ressource 的 AJAX 请求更新我的用户实体的一些数据。
这是我的 AJAX 请求:
this.$http.post('/profile/edit', {
description: this.description
}).then(response => {
console.log(response);
}, response => {
console.log(response);
});
这是我收到此 AJAX 请求的控制器:
/**
* @Route("/edit", name="profile_edit")
* @Method({"POST"})
*/
public function profileEditAction(Request $request) {
if ($request->isXmlHttpRequest()) {
/* @var User $user */
$user = $this->getUser();
$description = $request->request->get( 'description');
if (isset($description)) {
$user->setDescription($description);
$this->getDoctrine()->getManager()->flush($user);
return new Response('Updated User description with success !');
}
return new Response('No description parameter found');
}
return $this->redirectToRoute('homepage');
}
我的问题是,每次我尝试使用从我的请求中获取参数时$request->request->get('PARAMETER_NAME')
,它都会返回一个空值。
虽然我从浏览器显示我的请求,但我清楚地看到我正在发送一些东西:
完整的 AJAX 请求:https ://i.gyazo.com/825ea438b09e4df8d8287555a1c841a6.png
我希望有人可以帮助我解决这个问题,谢谢!