JQuery Ajax with ajaxsend

From CoderLearner
Jump to: navigation, search

Description

Whenever the ajax request occurs, the $.ajaxSend event trigger. Any and all handlers that include in $.ajaxSend 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() {
            $('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;
            });
            // before ajax requests send, the $.ajaxSend execute 
            //before it ajax request is about to be sent.
            $('#content_progress').ajaxSend(function(){
               $(this).html('Trigger AjaxSend');
               $(this).fadeIn();
            });
           
         });
      </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>

Try It