$.ajax({
type: "POST",
url: "core/login.php",
data: userInfo,
contentType : "application/x-www-form-urlencoded; charset=UTF-8",
success: function(msg){
if ($.trim(msg) == "success")
{
$('#status').load('home.php #status'); //refresh status: now shows as logged in
}
else
{
$('#error').html(msg); //this statement will execute whatever "$error" in login.php is, as html
$('#error').fadeIn(500).show();
}
}
});
Basically, I have a login form for a website. login.php processes userInfo (containing username and password), then returns either "success" or "error". If success, show user as logged in without refreshing the page (just refresh a div). If it fails, WITHOUT refreshing the page, show the error what the problem/failure was.
In Chrome and Safari, everything works fine. But in IE8 and Firefox, when there is a login error, the user is redirected to a new page showing the error (but I want the user to STAY on the same page hence I'm using Ajax). When there is success, instead of refreshing the status div and showing the status now as logged in, the message "success" is shown, again on a new page.
How can I fix this problem so that in all browsers, there is NO refresh during the entire login process? Thank you very much!