I have a controller that I call with Ajax. Inside this controller I have a condition, like
if($a == 10){
return $this->redirectToRoute('form_finish');
}
But when the condition is satisfited, I don't have the redirect
I have a controller that I call with Ajax. Inside this controller I have a condition, like
if($a == 10){
return $this->redirectToRoute('form_finish');
}
But when the condition is satisfited, I don't have the redirect
You call the controller in ajax but do you manage the response.
You have to redirect from the browser if the condition is satisfied or handle the ajax response and load the content in the DOM.
I solved it by doing something like this :
In controller i put the redirect handler in Jsonresponse :
//return $this->redirectToRoute('fos_user_security_logout');
$response = new JsonResponse(array(
'route' => $this->get('router')->generate('fos_user_security_logout'),
'message' => 'You may choose on option'));
return $response;
And in ajax
success: function(response,xhr){
//This is for the redrection in front page
if(response.route) { window.location.href=response.route;}
Hope it helps someone