The ajax
if I insert the data correctly and if the data is sent in the same way.
The only problem is that I only run the error message once.
In other words, if I write the current password wrong twice, the ajax returns me as a response that the password is not valid, if I enter the current password wrong again, Ajax
it no longer shows me the personalized error message.
I have to reload the page for it to show me the error messages.
Can you explain to me what the problem is with the code Ajax
, how to solve this error that appears in it.
ajax
<script type="text/javascript">
$(document).ready(function() {
var frm = $('#resetform');
frm.submit(function(e){
e.preventDefault();
var formData = frm.serialize();
formData += '&' + $('#submit_btn').attr('name') + '=' + $('#submit_btn').attr('value');
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: formData,
success: function(data){
$('#message').html(data).delay(3000).fadeOut(3000);
},
error: function(jqXHR, textStatus, errorThrown) {
$('#message').html(textStatus).delay(2000).fadeOut(2000);
}
});
});
});
</script>
Form
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<form name="resetform" action="changepass.php" id="resetform" class="passform" method="post" role="form">
<h3>Change Your Password</h3>
<br />
<label>Enter Old Password</label>
<input type="password" class="form-control" name="old_password" id="old_password">
<label>Enter New Password</label>
<input type="password" class="form-control" name="new_password" id="new_password">
<label>Confirm New Password</label>
<input type="password" class="form-control" name="con_newpassword" id="con_newpassword" />
<br>
<input type="submit" class="btn btn-warning" name="password_change" id="submit_btn" value="Change Password" />
</form>
You are hiding the message with
fadeOut
, as by default it is visible, after the first round it will be hidden, you should show it withfadeIn
Change the line:
By: