Answer the question
In order to leave comments, you need to log in
How to submit a form via AJAX in Symfony2?
How to connect AJAX submit to Twig form?
Answer the question
In order to leave comments, you need to log in
You describe in JavaScript sending to the controller for ajax.
Or, if the controller accepts not only ajax, you can check for XmlHttpRequest and return JSON.
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em->persist($entity);
$em->flush();
if ($request->isXmlHttpRequest()) {
return new JsonResponse([
'id' => $entity->getId(),
]);
}
return $this->redirectToRoute('route');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question