URL参数设置为值
test.html 。我们使用回调函数的两个参数,分别是
data 和
status ,其中第一个参数保存数据
在输出中,我们可以看到从服务器加载的数据,并且请求的状态为
成功。
test.html
<h1> Hello World </h1> <h2> Welcome to the lidihuo.com </h2>
Example2.html
<!DOCTYPE html> <html> <head> <title> jQuery get() method </title> <script src = "/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> </head> <body> <h3> This is an example of using the get() method in jQuery </h3> <p> Click the following button to see the effect. </p> <button> Click me </button> <p id = "p1"> </p> <p id = "p2"> </p> <script> $(document).ready(function() { $("button").click(function() { $.get("test.html", function(data,status) { document.getElementById("p1").innerHTML = data; document.getElementById("p2").innerHTML = "Status: " + status; }); }); }); </script> </body> </html>
输出
This is an example of using the get() method in jQuery