In previous article, we discussed few JQuery's AJAX functions. In this article, we will cover $.ajax() and its supporting functions. I used below script, that will explain the Ajax functions.
<script type="text/javascript">
$(function() {
$.ajaxSetup({ url: 'account/getdata'
});// Specify default values for all AJAX requests.
$('#title').ajaxStart(function()
{ $(this).html('<div>Ajax
Call started.</div>'); });//Called on
Ajax Call
$('#title').ajaxComplete(function(event,
request, settings) { $('<div>Ajax Call
Completed.</div>').appendTo($(this));
});// Called on Ajax call completes
$('#title').ajaxStop(function()
{ $('<div>Ajax Call Stopped.</div>').appendTo($(this)); });//Called when no
pending AJAX requests
$('#title').ajaxSuccess(function()
{ $('<div>Ajax Call Succeed.</div>').appendTo($(this)); });//Called When
Request is succeed
$('#title').ajaxError(function(e,
xhr, settings, exception) { $('<div>Ajax Call
Completed.</div>').appendTo($(this));
});//Called when Error occurs like invalid url...
$.ajax({
type: "POST",
data: {
firstname: "test", lastname: "123" },
success: function(data) {
var s = '<div>Loaded
' + data.fullName + '.</div>';
$(s).appendTo($('#title'));
}
}); // Makes a AJAX called
$.ajax({
type: "POST",
data: {
firstname: "test", lastname: "1234" },
success: function(data) {
var s = '<div>Loaded
' + data.fullName + '.</div>';
$(s).appendTo($('#title'));
}
}); // Makes a Another AJAX called
});
</script>

Join the conversation! Your thoughts help the community grow.