Assume:
1).my login form have two field enrollment,password with one button called login(submit)
2). My backend script login.php is fine no error there
here is my code for sending data via login form and comparing it to backend,now the problem is when i provide right password and enrollment which are needed for login,the event successfully completed but when i provide the wrong credentials its not showing an error message as displayed in ajax() error:function().although the message is displayed for a while when i double click the login button and then page automatically gets refreshed.can anyone help me out to getting error message when wrong password is provided for enrollment
$(function(){
/*$('#err').hide();*/
$('.err').hide();
/*$('.error').hide();*/
$('#eno').blur(function(){
var eno = $('input#eno').val();
if(eno == ""){
$('#err_eno').show();
$('input#eno').focus();
return false;
}else{
$('#err_eno').hide();
}
});
$('#pw').blur(function(){
var pw = $('input#pw').val();
if(pw == ""){
$('#err_pw').show();
$('input#pw').focus();
return false;
}else{
$('#err_pw').hide();
}
});
$('#submit_btn').click(function(){
var dataString = $('#log').serialize();
//alert (dataString);return false;
$.ajax({
type:"POST",
url:"script/login.php",
data:dataString,
success:function(){
window.location='profile.php';
},
error:function(){
$('#err').html("<p>Provide right combination</p>");
}
});
return false;
});
});
The error function in called when a request fails
, In your case the ajax function is executed successfully. What you have to do is set the ajax function's dataType property to json and pass a json array as response from server. See more info hereExample below:
});
Your login.php
I hope this is helpful.
Well your Success function is always executed, Try with the following implementation:
login.php