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