How to use ajaxSend() Method in JQuery AJAX

In this article, I will explain use of ajaxSend() Method in JQuery AJAX.
  • 4385

Query AJAX ajaxSend() Method

  • ajaxSend() method add a function to run when an AJAX requests is about to be sent.
  • ajaxSend() method is a AJAX Event.

Syntax

$(selector).ajaxSend(function(event,xhr,options))

function(event,xhr,options)  The function is run when the request is fail.
 parameters:

  • event - Event parameter contains the event object.

  • xhr - xhr parameter contains the XMLHttpRequest object.

  • options - option parameter contains the options used in the AJAX request.

 

Example

The following example show the use of ajaxSend() method.

 

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("div").ajaxSend(function (e, xhr, opt) {

            $(this).html("Requesting " + opt.url);

        });

        $("button").click(function () {

            $("div").load("ajaxsend_demo.aspx");

        });

    });

</script>

</head>

<body>

<div><h2>ajaxSend() method example</h2></div>

<button>click for send request</button>

</body>

</html>

Output

send.jpg 

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.