What is the ajaxSend() method in jQuery?
In jQuery, the ajaxSend() method is used to specify a function that runs when an AJAX request is about to be sent.
Syntax
$(document).ajaxSend(function(event, xhr, options));
Parameters
This method accepts a mandatory function that accepts the following parameters:
event: This is the event object.xhr: This is the instance of the XMLHttpRequest object.options: These are the options that are used in AJAX requests.
Example
The following tab will show us the ajaxSend() function in action:
Note: Press the “Get Product Data” button to see the
ajaxSend()function in action.
Code explanation
We made a GET request on https://reqres.in/api/products to fetch some product details.
Just before the AJAX request is about to be sent, the ajaxSend() method will be invoked.