我正在使用jQuery编辑我在Symfony中构建的表单.
我在jQuery对话框中显示该表单,然后提交它.
数据在数据库中正确输入.
但我不知道是否需要将一些JSON发送回jQuery.其实我对JSON的事情有点困惑.
假设我在我的表中添加了一行jQuery,当我提交表单然后提交数据后,我想发回那些行数据,以便我可以动态添加表行来显示添加的数据.
我很困惑如何才能获得这些数据
这是我目前的代码
$editForm = $this->createForm(new StepsType(), $entity);
$request = $this->getRequest();
$editForm->bindRequest($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->render('::success.html.twig');
}
Run Code Online (Sandbox Code Playgroud)
这只是带有成功消息的模板
我正在编写一个应用程序,该应用程序使用 ReactJs 作为localhost:3001 的前端,使用 Symfony 作为后端localhost:3000,并且为了启用跨源通信,我在 Symfony 中使用“cors-bundle”。现在我想在用户登录时创建一个Cookie,但它似乎没有创建!
感谢您的帮助,
这是用户登录时 Symfony 中的代码:
use Symfony\Component\HttpFoundation\Cookie;
$cookie = new Cookie( 'my_cookie', 1, strtotime('tomorrow') );
$res = new Response();
$res->headers->setCookie( $cookie );
return new JsonResponse($res);
Run Code Online (Sandbox Code Playgroud)
这也是我尝试过的:
$res->headers->setCookie(Cookie::create('my_cookie', 1));
return new JsonResponse($res);
Run Code Online (Sandbox Code Playgroud)