Ajax Request Problem

Hi guys,

following situation. I submit a form with an ajax button and I want to update a div. Everything is working, but how can I tell the application to make a redirect to another page if a specific situation occurs in the controller. Everytime I make a redirect, the redirect is only rendered in the div to be updated.

So how can I change the request, so that not only the div is updated?

Thx in advance!

I think the simplest way is to return


<script>window.location.href = 'redirect url';</script>

in the controller.

Unfortunately, I’m not quite sure that the script will be executed.

But you always can redefine success handler and do redirect from there.


success: function(data) {

    if (data.redirect) { // should be set in controller, of course

        window.location.href = data.redirect;

    }

    else {

        // something else

    }

}

You can redirect the page on ajax success function using window.location.href When you use ajax submit.

In your case, You sent the request to controller(through ajax) and controller redirect to another page and fetch the result and render the data (based on page information) to ajax success function.

And in this success function I could only redirect when a specific situation occured… I could set a status in the controller and depending on that status I can perform an action in the success function.

I will try it, thx!

Hey guys,

just managed the redirect with JSON response from the controller. Therefore I had to specify JSON as data type in the ajax button. But no I can’t render normal HTML anymore, because JSON is expected. Is there a way to combine JSON and HTML answer?

Thx!