Skip to content Skip to sidebar Skip to footer

Redirecting Main Window From Ajax Call

I have a ajax call to a controller that checks for authentication, when no authentication exists it sends the call onwards to the signin controller who checks if it is a xhr reques

Solution 1:

Are there any errors appearing in the console?

Would it not be easier to respond to "js" and render a js template with something like:

window.location = "http://localhost:3000/signin"

On a bit of a tangent, should you really be redirecting to "localhost:3000" absolutely anyway? Maybe there is a different solution?

Solution 2:

You will probably need to handle the response from the ajax request and redirect via JavaScript:

window.location = urlToDirectTo;

I think most browsers will redirect the ajax request itself, not the page from which the ajax request was made. Here's an answer to a similar question that details the solution.

Post a Comment for "Redirecting Main Window From Ajax Call"