How to disable some jQuery global Ajax event handlers for a request?



Use the global error handler to receive a few of the parameters that jQuery can provide. After that add the suppressErrors: true.  You can try to run the following code to disable some jQuery global Ajax event handlers for a request:

Live Demo

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){   $("div.log").ajaxError(function(evt, xhr, settings) {     if(settings.suppressErrors) {         return;     }     $(this).text( "ajaxError handler is triggered" );  });    $("button.trigger").click(function() {     $("div.log").text('');     $.ajax("ajax/missing.html");  });  $("button.triggerSuppress").click(function() {     $("div.log").text('');     $.ajax( "ajax/missing.html", {         suppressErrors: true     });  }); }); </script> </head> <body> <button class="trigger">Trigger (process errors)</button> <button class="triggerSuppress">Trigger (won't process errors)</button> <p>Check log</p> <div class="result"></div> <div class="log"></div> </body> </html>
Updated on: 2020-06-15T09:06:07+05:30

534 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements