jQuery - AJAX ??() ???
jQuery load() ???
load() ???? ???? ???? ???? ??? ???? ??? ??? ????.
??:
$(selector).load(URL,data,callback);
?? URL ????? ????? URL? ?????.
??? ??? ????? ??? ?? ??? ?? ??? ?/? ? ??? ?????.
???? ?? ????? load() ???? ??? ? ???? ??? ?????.
??? ?? ??("demo_test.txt")? ?????.
<h2>jQuery AJAX 是個非常棒的功能!</h2> <p id="p1">這是段落的一些文本。</p>
"demo_test.txt" ??? ??? ??? <div> ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("/try/ajax/demo_test.txt"); }); }); </script> </head> <body> <div id="div1"><h2>使用 jQuery AJAX 修改文本內(nèi)容</h2></div> <button>獲取外部內(nèi)容</button> </body> </html>
??? ??? ?? ????. jQuery ??? URL ????? ??
? ???? "demo_test.txt" ???? id="p1"? ??? ???? ??? <div> ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("/try/ajax/demo_test.txt #p1"); }); }); </script> </head> <body> <div id="div1"><h2>使用 jQuery AJAX 修改文本</h2></div> <button>獲取外部文本</button> </body> </html>
??? ?? ????? load() ??? ????? ?? ??? ?????. ???? ???????. ?? ??? ??? ????? ??? ? ????.
responseTxt - ?? ?? ? ?? ???? ?????.
statusTXT - ?? ??? ?????.
xhr - XMLHttpRequest ??? ?????.
?? ???? ?? ? ????? ?????. load() ???? ???????. load() ???? ???? "?? ???? ????? ???????!"? ????, ???? ??? ?? ?? ???? ?????. text ??.html ??:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("/try/ajax/demo_test.txt",function(responseTxt,statusTxt,xhr){ if(statusTxt=="success") alert("外部內(nèi)容加載成功!"); if(statusTxt=="error") alert("Error: "+xhr.status+": "+xhr.statusText); }); }); }); </script> </head> <body> <div id="div1"><h2>使用 jQuery AJAX 修改該文本</h2></div> <button>獲取外部內(nèi)容</button> </body> </html>
?? HTML ??? ???(??? ??? ?? ??? ? ??) jQuery AJAX load() ???? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> </head> <body> <div class="comment"> 已有評論: </div> <div class="comment"> <h6>張三:</h6> <p class="para">沙發(fā)。</p> </div> <div class="comment"> <h6>李四:</h6> <p class="para">板凳。</p> </div> <div class="comment"> <h6>王五:</h6> <p class="para">地板。</p> </div> </body> </html>