I've got the following code that checks for a username and password, and then redirects to a new page if it's successful. It works on Firefox just fine, but when I try it on IE 9, it just sits and hangs. What do I need to do to make this work on IE?
username=$("#user_name").val();
password=$("#password").val();
$.ajax({
type: "POST",
url: "login.php",
data: "name="+username+"&pwd="+password,
success: function(html){
console.log(html);
if(html=='true') {
window.location.replace("newpage.php");
} else {
$("#add_err").html("Wrong username or password.");
}
},
I've got the following code that checks for a username and password, and then redirects to a new page if it's successful. It works on Firefox just fine, but when I try it on IE 9, it just sits and hangs. What do I need to do to make this work on IE?
username=$("#user_name").val();
password=$("#password").val();
$.ajax({
type: "POST",
url: "login.php",
data: "name="+username+"&pwd="+password,
success: function(html){
console.log(html);
if(html=='true') {
window.location.replace("newpage.php");
} else {
$("#add_err").html("Wrong username or password.");
}
},
Share
Improve this question
asked Jun 5, 2012 at 11:35
NinjaCatNinjaCat
10.2k9 gold badges46 silver badges65 bronze badges
6 Answers
Reset to default 12First in regard to the other answers: location.replace is not the same as just changing the location.href, it reacts with the history differently, and in many cases location.replace is better for the user experience, so lets not throw the towel in on location.replace quite so quickly!
So I just tested location.replace in IE9 on my machine and it worked.
Then I tested console.log on my IE9 and it choked (that apparently only works if a certain developer panel or tab or something is open I'm reading, though I don't have much experience with IE9's dev tools to say that for sure).
I'm betting your problem is not the location.replace function, but in fact the console.log function that is right before it!
Well I've been a while looking how to change window.location on IE and this works for me:
var targetlocation = "mylocation";
setTimeout(changeURL,0)
function changeURL()
{
window.location = targetlocation;
}
You don't need replae.
if(html=='true') {
window.location = "newpage.php";
// or
window.location.href = "newpage.php";
} else {
$("#add_err").html("Wrong username or password.");
}
try
window.location.href = 'newpage.php'
window.location = "newpage.php";
or
window.location.href = "newpage.php";
if(html) {
window.location.href = "filename.php";
} else {
$("#add_err").html("Wrong username or password.");
}