jQuery ajaxSend()

Introduction

Change the content of a <div> element when an AJAX requests is about to be sent:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   ww w.j  a v a2s .c  o m
<script>
$(document).ready(function(){
  $(document).ajaxSend(function(e, xhr, opt){
    $("div").append("<p>Requesting " + opt.url + "</p>");
  });
  $("button").click(function(){
    $("div").load("ajax.txt");
  });
});
</script>
</head>
<body>

<div><h2>Here</h2></div>

<button>Change Content</button>

</body>
</html>

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

This method should only be attached to document.

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

MutliLlineTable:/*from  ww w.j  a va 2s .c o  m*/

Parameter                       Optional         Description

function(event,xhr,options)     Required.         Specifies the function to run if the request succeeds 
                                                  Additional parameters: 
                                                  event - contains the event object 
                                                  xhr - contains the XMLHttpRequest object 
                                                  options - contains the options used in the AJAX request



PreviousNext

Related