jquery form ajax complete code example

Example 1: all ajaxcomplete event

//when document load and complete all ajax response this event will fire only one time
$(document).ajaxStop(function(){
  alert("All AJAX requests completed");
});

Example 2: jquery ajax form submission

$(function() {
  $('form.my_form').submit(function(event) {
    event.preventDefault(); // Prevent the form from submitting via the browser
    var form = $(this);
    $.ajax({
      type: form.attr('method'),
      url: form.attr('action'),
      data: form.serialize()
    }).done(function(data) {
      // Optionally alert the user of success here...
    }).fail(function(data) {
      // Optionally alert the user of an error here...
    });
  });
});