I am using Ajax for ASynchronous post back and using Deferred object to wait for the response till i perform additional task based on the response.
Response message i am getting from PHP page and based on that i am performing further action on current page I want to know how do i pass response message(received from PHP page) from my Ajax function to deferred object. Also is my code correct?
Here is my code:
jQuery(document).ready(function($) {
var action = jQuery('#contactForm').attr('action');
function checkfunction() {
$("#contactForm").submit(function() {
return $.ajax({
type: "POST",
url: action,
dataType: "html",
data: $(this).serialize(),
beforeSend: function() {
//$("#loading1").show();
},
success: function(response) {
}
// return response;
})
return false;
});
}
checkfunction()
.done(function(response) {
if (response == "success") {
// Display success message
} else {
// Display Error message
}
})
.fail(function(x) {
// Display Error message
});
});