ajaxSend() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:ajaxSend

Description

The ajaxSend() method sets a function to run when an AJAX requests is about to be sent.

Syntax

Parameter Description
function(event,xhr,options) Required.

Additional parameters:

  • event - the event object
  • xhr - the XMLHttpRequest object
  • options - the options used in the AJAX request

The following code shows how to change the content of a <div> element when an AJAX requests is about to be sent:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(document).ajaxSend(function(e, xhr, opt){
        $("div").append("<p>Requesting " + opt.url + "</p>");
    });/*from   www.  j  a  va2  s. c  o m*/
    $("button").click(function(){
        $("div").load("demo_ajax_load.asp");
    });
});
</script>
</head>
<body>

<div><h2>Let AJAX change this text</h2></div>

<button>Change Content</button>

</body>
</html>

Related Tutorials