Home >>jQuery Tutorial >jQuery ajaxSend() Method

jQuery ajaxSend() Method

jQuery ajaxSend() Method

jQuery ajaxSend() method in jQuery is used to specifies a function to run when an AJAX requests is about to be sent.

Syntax
$(document).ajaxSend(function(event,xhr,options))

Parameter Values

Parameter Description
function(event,xhr,options) It is a Required parameter and is used to Specifies the function to run if the request succeeds
Additional parameters:
  • event – Used to contains the event object
  • xhr – Used to contains the XMLHttpRequest object
  • options – Used to contains the options used in the AJAX request
Here is an Example of jQuery ajaxSend() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).ajaxSend(function(e, xhr, opt){
$(".DiV").append("<p>Requesting " + opt.url + "</p>");
});
$(".btn1").click(function(){
$(".DiV").load("demo_ajax_load.asp");
});
});
</script>
</head>
<body>
<div class="DiV"><h2>Change this text</h2></div>
<button class="btn1">Click Me to Change Content</button>
</body>
</html>

Output:

Change this text