Hearaman
Hearaman

Reputation: 8726

Error in jquery ajax() method?

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);
        }
   });

Upvotes: 0

Views: 120

Answers (4)

Veger
Veger

Reputation: 37915

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

For more information check out the w3schools page on this topic

Upvotes: 0

genesis
genesis

Reputation: 50982

window.location.href = 'user/index.php';

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

Upvotes: 0

Mr.J4mes
Mr.J4mes

Reputation: 9266

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

Upvotes: 0

Mrchief
Mrchief

Reputation: 76248

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.

Upvotes: 1

Related Questions