I hope the following answer is help you.
$('#formEmp').submit(function(event) {
//Validate using jquery validator
if (!$('#formEmp').valid()) {
return false;
}
// abort any pending request
if (request) {
request.abort();
}
// setup some local variables
var $form = $(this);
// let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
$inputs.prop("disabled", false);
// serialize the data in the form
var serializedData = $form.serialize();
// let's disable the inputs for the duration of the ajax request
// Note: we disable elements AFTER the form data has been serialized.
// Disabled form elements will not be serialized.
$inputs.prop("disabled", true);
// fire off the request to /form.php
request = $.ajax({
url: "saveEmp",
type: "post",
data: serializedData
});
// callback handler that will be called on success
request.done(function(response, textStatus, jqXHR) {
// log a message to the console
alert("Saved Successfully");
initForm();
});
// callback handler that will be called on failure
request.fail(function(jqXHR, textStatus, errorThrown) {
// log the error to the console
alert(textStatus);
});
// callback handler that will be called regardless
// if the request failed or succeeded
request.always(function() {
// reenable the inputs
$inputs.prop("disabled", false);
});
// prevent default posting of form
event.preventDefault();
});