jQuery ajaxSetup()
handle error
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/*w w w . j a v a 2s. c om*/ <script> $(document).ready(function(){ $("button").click(function(){ $.ajaxSetup({url:"wrongfile.txt",error:function(xhr){ document.getElementById("demo").innerHTML = "An error occured: " + xhr.status + " " + xhr.statusText; }}); $.ajax(); }); }); </script> </head> <body> <p id="demo"></p> <div></div> <button>Get</button> </body> </html>