-3

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

monkeyUser
  • 4,301
  • 7
  • 46
  • 95

2 Answers2

2

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.

1

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

stomerfull
  • 11
  • 2