jQuery ajaxComplete()

jQuery ajaxComplete() method allows you to run function after Ajax request complete.

Syntax

$(document).ajaxComplete(function(event,xhr,settings))

Specification

  • event:contains an event object
  • xhr:contains the XMLHttpRequest object
  • settings:settings used in the AJAX request.

Examples

Show a message when an Ajax request completes.

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery ajaxComplete() Example </title>
</head>
<body>
<div id="txt"><h2>Change Text By Ajax</h2></div>
<button>Change Content</button>
</body>
</html>
Javascript
$(document).ready(function(){
     $("button").click(function(){
        $("#txt").load("ajax.php");
    });
     $(document).ajaxComplete(function(event, xhr, settings){
       $( "#txt" ).append("<p>Request Complete.</p>");
    });
});