JQuery Ajax with ajaxerror

From CoderLearner
Jump to: navigation, search


Whenever an Ajax request is completed but with an error, it will triggers the $.ajaxError() event to be sent.

Example 1

This example shows how the $.ajaxError event trigger when we try to send ajax request with the invalid or non-existed server side script.

<!DOCTYPE html>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         $(document).ready(function() {
               var agev = $('input[name="age"]').val();
         // it will never send, because age.php2 is not existed
                     $('#content').html('Something wrong, please try again!');
                  else {
               return false;
            // when an ajax request completes and with an error, 
            // it will trigger this $.ajaxError 
               $(this).html('Invalid Request');
      <div id="content_progress"></div>
      <div id="content"></div>
      <form name="frm_userinfor" method="post">
         Age:<input type="text" name="age"/><br/>
         <input type="submit" name="check" value="Check" />

Try It