jQuery ajaxStart()

Introduction

Show a "loading" indicator image when an AJAX request starts:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//w  ww . j a v  a2  s.co  m
<script>
$(document).ready(function(){
  $(document).ajaxStart(function(){
    $(this).html("<img src='image3.png'>");
  });
  $("button").click(function(){
    $("div").load("ajax.asp");
  });
});
</script>
</head>
<body>

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

<button>Change Content</button>

</body>
</html>

The ajaxStart() method sets a function to be run when an AJAX request starts.

This method should only be attached to document.

Syntax

$(document).ajaxStart(function());
Parameter Optional Description
function() Required. the function to run when the AJAX request starts



PreviousNext

Related