Home >Web Front-end >JS Tutorial >jQuery's load() method and its callback function usage example_jquery

jQuery's load() method and its callback function usage example_jquery

WBOY
WBOYOriginal
2016-05-16 16:07:391377browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn