Home >Web Front-end >JS Tutorial >jQuery's load() method and its callback function usage example_jquery
The example in this article describes jQuery’s load() method and its callback function usage. Share it with everyone for your reference. The details are as follows:
The following js code demonstrates the use of jQuery's load() method, and demonstrates the use of the load method with callback function (callback)
<!DOCTYPE html> <html> <head> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("demo_test.txt",function(responseTxt,statusTxt,xhr){ if(statusTxt=="success") alert("External content loaded successfully!"); if(statusTxt=="error") alert("Error: "+xhr.status+": "+xhr.statusText); }); }); }); </script> </head> <body> <div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div> <button>Get External Content</button> </body> </html>
I hope this article will be helpful to everyone’s jQuery programming.