把a.html裏面的某一部份的內容加載到b.html的一個div裏。
好比:加載a.html裏面的<div id=「row"></div>這個div裏面的全部內容加載到b.html的這個div裏<div id="content"></div>
用jquery ajax 能夠實現
假設 a.html 和b.html在同一目錄
b.html html
1 <script > 2 $(document).ready(function() { 3 bodyContent = $.ajax({ 4 url: "b.html", 5 global: false, 6 type: "POST", 7 data: ({ 8 id: this.getAttribute('row') 9 }), 10 dataType: "html", 11 async: false, 12 success: function(msg) { 13 alert(msg); 14 } 15 }) 16 }); 17 </script>
2、juqery $.ajax 請求另外一個html頁面的指定的「一部分」加載到本頁面div,重點是一部分數據加載到本頁面divjquery
大至思路以下:ajax
1 $.ajax( { 2 url: url, //這裏是靜態頁的地址 3 type: "GET", //靜態頁用get方法,不然服務器會拋出405錯誤 4 success: function(data){ 5 var result = $(data).find("另外一個html頁面的指定的一部分"); 6 $("本頁面div").html(result); 7 8 9 } 10 });
或參考下面的代碼:服務器
1 $(function(){ 2 $.ajax({ 3 type:"POST", 4 url:"LoginLoadArticle.ashx", 5 data: "type="+escape("最新公告") , 6 success:function(msg){ 7 $(".gonggao").html(msg); 8 }, 9 error:function(XMLHttpRequest, textStatus, thrownError){} 10 }) 11 12 })
若是參數不明白能夠參考async
3、JQuery中$.ajax()方法參數詳解this