Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Error Handling with Promises</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <button id="load">Load data</button> <pre id="out"></pre> <script> $("#load").on("click", function(){ $.get("https://httpbin.org/status/500") .done(function(data){ $("#out").text("ok"); }) .fail(function(xhr){ $("#out").text("error " + xhr.status); }); }); </script> </body> </html>
Output