I am posting this question after searching alot on google.I am posting my FORM on Jquery POST method and doing validation in codeigniter.
If a field is empty,it show me error message,BUT when i fill that field and click again,this time there is no error but it do not remove previous error message. Here is my code
var parameters = $("#frm_rexpert").serialize();
var form = $("#frm_rexpert");
$.post(siteurl+'/services/req_expert', parameters, function(data) {
if (data.status == true) {
//show success message
$("#msg_exp").show();
setTimeout(function() { $("#msg_exp").hide(); }, 5000);
}else{
$.each(data.errors, function(key, val) {
$('[name="'+ key +'"]', form).after(val);
})
}
}, "json");
On server side
$this->form_validation->set_rules($rules);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if ($this->form_validation->run())
{//do your code
}else{
$errors = array();
// Loop through $_POST and get the keys
foreach ($this->input->post() as $key => $value)
{
// Add the error message for this field
$errors[$key] = form_error($key);
}
$response['errors'] = array_filter($errors); // Some might be empty
$response['status'] = FALSE;
}
header('Content-type: application/json');
exit(json_encode($response));
MY Question is "If there is no error,I need to clear all old error messages"