ajaxStart() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:ajaxStart

Description

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

Syntax

Parameter Description
function() Required. Specifies the function to run when the AJAX request starts

The following code shows how to show a "loading" indicator image when an AJAX request starts:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(document).ajaxStart(function(){
        $(this).html("<img src='http://java2s.com/resources/a.png'>");
    });//www .j a va  2 s .c om
    $("button").click(function(){
        $("div").load("demo_ajax_load.asp");
    });
});
</script>
</head>
<body>

<div><h2>Let AJAX change this text</h2></div>

<button>Change Content</button>

</body>
</html>

Related Tutorials