Reputation: 79696
Is it possible to redirect a web site from the server on an ajax request?
Eg.
I need to redirect it to the same url but with a hash.
Using window.location.href = http://www.myapp.com#page=main won't work since it will just update the location with the hash.
Upvotes: 2
Views: 207
Reputation: 50976
Aeah, it is. You can use meta or javascript redirect. Just append following code into an ajax reponse & make sure that reponse is placed into actual page
<script>document.location.href='newpage.php'</script>
or to refresh, return
<script>document.location.reload(1);</script>
Upvotes: 2
Reputation: 887469
No.
An AJAX request just returns data to the client; the browser does not act on it at all.
Instead, you need to make the server tell your client code to do a redirect in its response, then write client code to check whether the server asked it to redirect and navigate to the new location.
Upvotes: 2