load
<!DOCTYPE html> <html> <head> <script src="/jquery/jquery-1.11.1.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("/example/jquery/demo_test.txt h2","data",function(responseTxt,statusTxt,xhr){alert("this is a test"+responseTxt)}); }); }); </script> </head> <body> <div id="div1"><h2>使用 jQuery AJAX 来改变文本</h2></div> <button>获得外部内容</button> <pre> <h2>jQuery and AJAX is FUN!!!</h2> <p id="p1">This is some text in a paragraph.</p> </pre> </body> </html>
放到http://www.w3school.com.cn/上执行吧
更多例子详见<div><a href="http://www.w3school.com.cn/jquery/jquery_ajax_load.asp">w2school</a></div>
get:从指定的资源请求数据
@H_404_12@语法:
$.get(URL,callback);
必需的URL参数规定您希望请求的 URL。
可选的callback参数是请求成功后所执行的函数名。第二个参数是回调函数。第一个回调参数存有被请求页面的内容,第二个回调参数存有请求的状态。
下面的例子使用 $.get() 方法从服务器上的一个文件中取回数据: