JQuery Ajax callback

 

In this example, we are going to use callback function and error method. when you click the button then load() method will run and alert box message will appear on the screen. It can be an error message if the website is not valid.

 
 
 
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $(".box").load("https://appwrk.com/", (responseTxt, statusTxt, jqXHR)=>{ if(statusTxt == "success"){ alert("Your Website loaded successfully!"); } if(statusTxt == "error"){ alert("Error: " + jqXHR.status + " " + jqXHR.statusText); } }); }); }); </script> </head> <body> <div class="box"> <h2 style="color: darkgreen">Jquery ajax load with error</h2> </div> <button class="button">Lets change website</button> </body> </html>
Output