w3resource
jquery exercises

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

jQuery Fundamental - I : Exercise-12

Register a handler to be called when Ajax requests complete with an error.

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 with an error.</title>
 </head>
 <body>
 <button class="trigger">Click to see the file content</button>
 <div class="result"></div>
 <p class="log"></p>
 </body>
 </html>

JavaScript Code :

$( document ).ajaxError(function() {
  $( ".log" ).text( "File not present." );
});

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

Used Methods :

  • .ajaxError() : Register a handler to be called when Ajax requests complete with an error. This is an Ajax Event.

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


Contribute your code and comments through Disqus.


ankara escort
kızılay escort