0

To redirect current page I use window.document.location() statement inside the ajax() function. But it is showing error(in firebug). There is no error in functionality request is going and response is comming properly. window.document.location('user/index.php'); statement creating the problem. How can I redirect this page to another if the msg=='YES'?

$.ajax({
          url:  "user_registration.php",
          type: "post",
          data: datastring,
          success: function(msg) {
              if(msg=='YES') {                                  
                   window.document.location('user/index.php');
              }
              else
                   $("#success").html(msg);
        }
   });
1
  • Don't you mean document.location.href = 'user/index.php' ? Commented Aug 24, 2011 at 14:19

4 Answers 4

1

Simply say window.location = newLocation; in your success handler to redirect to new location.

$.ajax ({
     url:  "user_registration.php",
     type: "post",
     data: datastring,
     success: function(msg) {
          if(msg=='YES') {                                  
               window.location = 'user/index.php';
          }
          else {
           $("#success").html(msg);
          }
     }
});

More on window.location here.

Sign up to request clarification or add additional context in comments.

Comments

0

should the relative URL be "/user/index.php" ?

1 Comment

Then it becomes absolute (starting at the current domain name)
0
window.location.href = 'user/index.php';

don't forget, YES must be YES, not yes

Comments

0

Use window.location.replace("http://www.w3schools.com") that should work.

For more information check out the w3schools page on this topic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.