Example of jQuery's load of method and its callback function usage
- 2020-05-19 04:07:28
- OfStack
This article illustrates the load() method of jQuery and its use of the callback function. Share with you for your reference. The details are as follows:
The js code below demonstrates the use of the load() method for jQuery and the load method to bring back the 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 is helpful to you in jQuery programming.