w3resource

jQuery: Register a handler to be called when Ajax requests complete

jQuery Fundamental - I : Exercise-11

Register a handler to be called when Ajax requests complete.

Note: Set up a basic Ajax load request, attach the event handler to the document. Now make an Ajax request using any jQuery method

Sample solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Register a handler to be called when Ajax requests complete.</title>
</head>
<body>
<div class="jquery">jQuery: Click here</div>
<div class="result"></div>
<div class="log"></div>
</body>
</html>

JavaScript Code :

$( document ).ajaxComplete(function() {
  $( ".log" ).text( "Triggered ajaxComplete handler." );
});

$( ".jquery" ).click(function() {
  $( ".result" ).load( "https://www.w3resource.com/jquery-exercises/jq-ajax-test.html" );
});

Used Methods :

  • .ajaxComplete() : Register a handler to be called when Ajax requests complete. This is an AjaxEvent.

See the Pen jquery-fundamental-exercise-11 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Using jQuery insert a jQuery object (similar to an Array of DOM Elements) after all paragraphs.
Next: Register a handler to be called when Ajax requests complete with an error.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/jquery-exercises/1/jquery-fundamental-exercise-11.php