I am using jQuery ajax to submit a form. I have written php code in a different file to insert the form-data into a database table. How can I do the server side validation and show corresponding error message (e.g. this field cannot be empty)? I have no idea about how to solve this problem. jQuery function that does the submission is as follows
$('#form-add-button').click(function () {
$.ajax({
type: "POST",
url: 'addemployee.php',
data: $("#employee-form").serialize(),
success: function (response) {
showEmployeesData();
initInputValues();
},
error: function (response) {
alert('Error:' + response);
}
});
return false;
});