jQuery ajaxStart()

jQuery ajaxStart() method allows you to run function when the first Ajax request start.

Syntax

$(document).ajaxStart(function())

Specification

  • function():specifies the function when the first Ajax request start.

Examples

Show a message when an Ajax request start.

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery ajaxStart() Example </title>
</head>
<body>
<div id="txt"><h2>Get Ajax Content</h2></div>
<button>Change Content</button>
</body>
</html>
Javascript
$(document).ready(function(){
     $("button").click(function(){
        $("#txt").load("ajax.txt");
    });
     $(document).ajaxStart(function(){
        $("#txt").html("loading...");
    });
});