JQuery Ajax with ajaxStop

From CoderLearner
Jump to: navigation, search

Description

The $.ajaxStop() is occurred whenever the Ajax requests have completed. All any handlers that have been registered with the $.ajaxStop() method are executed at this time.

Example 1

<!DOCTYPE html>
<html>
   <head>
      <title>ajax</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <script>
         $(document).ready(function() {
                  
            $('#content_progress').ajaxStop(function(){
               $(this).html('Completed stop');
            });
      
            $('form[name="frm_userinfor"]').submit(function(){
               var agev = $('input[name="age"]').val();
         
               $.post('age.php',{'age':agev},
               function(data){
                  if(data=='failed'){
                     $('#content').html('Something wrong, please try again!');
                  }
                  else {
                     $('#content').html(data);
                  }
               });
               return false;
            });
         });
      </script>
   </head>
   <body>
      <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" />
      </form>
     
   </body>
</html>