I have been working with AJAX for a while now, I can get the form to submit via ajax, I can get the Div to reload via ajax, add, edit, delete via ajax. What i am aiming on now is better understanding on how to display error messages.
What I think is an error message Suppose a form asks for a name to be submitted, when the user does not enter his name and hits the submit button then the error message should be shown asking user the enter the information required.
At present I am managing this inside the success
part of AJAX, is this the right way to do it? If yes then what is AJAX error: function
for? Shouldn't the error message where user did not enter the required information be shown through error: function
?
This is what my AJAX
calls look like and I want to improve it.
$.ajax({
url: 'demo.php', //your server side script
data: $("#form").serialize(),
type: 'POST',
beforeSend: function () {
$('#dvloader').show();
},
success: function (data) {
$('#dvloader').hide();
$("#message").html(data);
}
});
I also wanted to know should hiding a loading gif be iside the success
as well, although it works but I want to know if this is the right way to do it.
I will really appreciate anyone's feedback on it.