Reputation: 8726
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
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
Reputation: 50982
window.location.href = 'user/index.php';
don't forget, YES must be YES, not yes
Upvotes: 0
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