How can I redirect the user from one page to another using jQuery -> Ajax? Thanks for your time.
-
1What have you tried? And why do you want to do this? Why not just use a link to send the user to another page? Or are you already using AJAX to do something and want to send the user after the callback?putvande– putvande2013-08-03 11:59:21 +00:00Commented Aug 3, 2013 at 11:59
-
2Using ajax to redirect is the exact opposite of it's intended use.adeneo– adeneo2013-08-03 12:03:34 +00:00Commented Aug 3, 2013 at 12:03
-
On success call of ajax set "window.location.reload=data.url" where url is the string you have returned from the called methodNitin Varpe– Nitin Varpe2013-08-03 12:28:25 +00:00Commented Aug 3, 2013 at 12:28
-
duplicate of stackoverflow.com/questions/503093/…Patrick W. McMahon– Patrick W. McMahon2015-05-01 14:57:27 +00:00Commented May 1, 2015 at 14:57
Add a comment
|
3 Answers
$.ajax({
url:"http://where.to/redirect",,
async:false,
});
This will load the url synchroniously, that means redirect the user "in jquery/javascript when using ajax". To "make a redirect page", write this:
<script type="application/javascript" language="javascript">
$.ajax({
url:"http://where.to/redirect",,
async:false,
});
</script>
... tada! We have a "a redirect page in jQuery/JavaScript when using ajax"! ;)
Comments
// Through an HTTP redirect
window.location.replace("http://stackoverflow.com");
// Through by clicking on a link
window.location.href = "http://stackoverflow.com";