一、jQuery加載一個html頁面到指定的div里
把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
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>
二、juqery $.ajax 請求另一個html頁面的指定的“一部分”加載到本頁面div,重點是一部分數據加載到本頁面div
大至思路如下:
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 })
如果參數不明白可以參考
三、JQuery中$.ajax()方法參數詳解