开发者

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 go开发者_如何学编程ing 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);
        }
   });


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.


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


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

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


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

For more information check out the w3schools page on this topic

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜