jQuery ajaxSend() Method

jQuery ajaxSend() method to be called before the AJAX request sent.

When an Ajax request is sent, jQuery triggers the ajaxSend event.

Syntax

Here is a syntax for ajaxSend() method

$(selector).ajaxSend( function(event, jqXHR, options) );
Parameter Type Description
function(event, jqXHR, options) Function Required. A specifies callback function to be run before the AJAX request sent.
Additional parameters
  • event - contains standard event object
  • jqXHR - contains the XMLHttpRequest object
  • options - contains plain object used in the AJAX request

Example

ajaxfile.html
<html>
  <body>
    <p>Ajax is use to jQuery to open URL documents with in the documents</p>
    <br />
    <p>AJAX = Asynchronous JavaScript and XML</p>
  </body>
</html>

Here, in this example ajaxSend() method call when click on button.

<!DOCTYPE html>
<html>
<head>
  <title>jQuery ajaxSend() event method</title>
  <script src="jquery-latest.min.js"></script>
  <script>
    $(document).ready(function() {
      $("button").click(function(event){
        $("#msg").load("ajaxfile.html");  
      });
      $(document).ajaxSend(function(event, jqXHR, options){
        $("#send").text("Requesting file: " + options.url );
      });
    });
  </script>
</head>
<body>
  <p id="send"></p>
  <button>Click here to call ajaxSend() method</button>
  <br /><br />
  <div id="msg" style="background-color:pink;">New content updates here</div>
</body>
</html>

Run it...   »