Javatpoint Logo
Javatpoint Logo

jQuery ajaxSend() method

The jQuery's ajaxSend() method is used to attach a function to run before an AJAX request is sent. It is an AJAX event that triggers when an AJAX request is about to be sent.


The ajaxSend() method accepts a single parameter which is defined as follows -

function(event, xhr, options): This is a mandatory parameter. It is a callback function that executes on the successful server request.

It also has three additional parameters named as event, xhr, and options. The additional parameters are defined as follows -

event: It includes the event object.

xhr: It includes the XMLHttpRequest object.

options: It includes the options used in the AJAX request.

Now, let's see a simple example of using the ajaxSend() method.


This is a simple example of using the ajaxSend() method. In this example, the function which is passed as the mandatory parameter of the ajaxSend() method will be triggered when the request is about to be sent. The triggered function will display an alert dialog box showing the URL of the requested page. This alert box will be displayed before the request is sent.

Here, there is an external file named as sample.txt that contains some data. We are using the load() method to load the external file from the server.

In the output, we can see the data loaded from the server. We have to click the given button to load the data from the external .txt file.



After the execution of the above code, the output will be -

jQuery ajaxSend() method

After clicking the given button, a dialog box will be displayed showing the URL of the requested page -

jQuery ajaxSend() method

After closing the dialog box, the data of the requested page will be displayed, as shown in the following screenshot.

jQuery ajaxSend() method

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA