jQuery加载一个html页面到指定的div里

一、jQuery加载一个html页面到指定的div里

把a.html里面的某一部份的内容加载到b.html的一个div里。
比如:加载a.html里面的<div id=“row"></div>这个div里面的所有内容加载到b.html的这个div里<div ></div>

用jquery ajax 可以实现
假设 a.html 和b.html在同一目录 
b.html 

jQuery加载一个html页面到指定的div里
 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>
jQuery加载一个html页面到指定的div里

二、juqery $.ajax 请求另一个html页面的指定的“一部分”加载到本页面div,重点是一部分数据加载到本页面div

大至思路如下:

jQuery加载一个html页面到指定的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 });
jQuery加载一个html页面到指定的div里

或参考下面的代码:

jQuery加载一个html页面到指定的div里
 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加载一个html页面到指定的div里


如果参数不明白可以参考

三、JQuery中$.ajax()方法参数详解

http://blog.csdn.net/chelen_jak/article/details/22742567

一、jQuery加载一个html页面到指定的div里

把a.html里面的某一部份的内容加载到b.html的一个div里。
比如:加载a.html里面的<div id=“row"></div>这个div里面的所有内容加载到b.html的这个div里<div ></div>

用jquery ajax 可以实现
假设 a.html 和b.html在同一目录 
b.html 

jQuery加载一个html页面到指定的div里
 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>
jQuery加载一个html页面到指定的div里

二、juqery $.ajax 请求另一个html页面的指定的“一部分”加载到本页面div,重点是一部分数据加载到本页面div

大至思路如下:

jQuery加载一个html页面到指定的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 });
jQuery加载一个html页面到指定的div里

或参考下面的代码:

jQuery加载一个html页面到指定的div里
 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加载一个html页面到指定的div里


如果参数不明白可以参考

三、JQuery中$.ajax()方法参数详解

http://blog.csdn.net/chelen_jak/article/details/22742567