最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery+Ajax+js實現(xiàn)請求json格式數(shù)據(jù)并渲染到html頁面操作示例

 更新時間:2020年06月02日 12:03:14   作者:wit_stan  
這篇文章主要介紹了jQuery+Ajax+js實現(xiàn)請求json格式數(shù)據(jù)并渲染到html頁面操作,結(jié)合實例形式分析了jQuery+Ajax請求json格式數(shù)據(jù)并渲染到html頁面相關(guān)步驟與操作技巧,需要的朋友可以參考下

本文實例講述了jQuery+Ajax+js實現(xiàn)請求json格式數(shù)據(jù)并渲染到html頁面操作。分享給大家供大家參考,具體如下:

1、先給json格式的數(shù)據(jù):

[
{"id":1,"name":"stan"},
{"id":2,"name":"jack"},
{"id":3,"name":"lucy"},
{"id":4,"name":"mary"},
{"id":5,"name":"jerry"},
{"id":6,"name":"tom"}
]

2、通過訪問html頁面,獲取并展示數(shù)據(jù):

方法一:

<!DOCTYPE html>
<html>
 <head>
 <title></title>
 </head>
 <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <body>
 <div id="test">
 
 </div>
 <script type="text/javascript">
  window.οnlοad=function(){
  //js代碼請求
  }
  $(function(){
    $.ajax({
   method:"post",
   url:"http://localhost:81/getpersons",/*這里要寫nginx訪問的全路徑*/
   data:{},
   dataType: "json",
   success: function(data){
    var str="<ul>";  
    $.each(data,function(i,items){   
    str+="<li>"+"ID:"+items.id+"</li>";
    str+="<li>"+"姓名:"+items.name+"</li>"; 
    });         
    str+="</ul>";   
    $("div").append(str); 
   }
   
  });
 
  })
 </script>
 </body>
</html>

方法二:

<!DOCTYPE html>
 
<html>
 <head>
 <title></title>
 </head>
 
 <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <body>
 <div id="test">
  <table border="1" cellspacing="1" cellpadding="1" id="a1">
         
  </table>
 </div>
 
 <script type="text/javascript">
  window.οnlοad=function(){
 
  //js代碼請求
  }
  $(function(){
    $.ajax({
   method:"post",
   url:"http://localhost:81/getpersons",/*這里要寫nginx訪問的全路徑*/
   data:{},
   success: function(data){
   alert(data);
   //將json數(shù)據(jù)轉(zhuǎn)換
   dd=eval("("+data+")");
 
   var htmls;
   for(var i=0;i<dd.length;i++){
     htmls="<tr>+<td>"+"id: "+dd[i].id+"</td>+<td>"+"name :"+dd[i].name+"</td>+</tr>";
     $("#a1").append(htmls);
   }
   }
   
  });
 
  })
 </script>
 </body>
</html>

更多關(guān)于jQuery相關(guān)內(nèi)容可查看本站專題:《jquery中Ajax用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論

石狮市| 嘉禾县| 辛集市| 卫辉市| 巴中市| 仙桃市| 桓台县| 安塞县| 龙口市| 富宁县| 邯郸县| 万宁市| 高雄县| 铜陵市| 齐齐哈尔市| 香河县| 伊川县| 晋宁县| 天门市| 寻乌县| 盘锦市| 吉林市| 麦盖提县| 鄂托克旗| 双辽市| 南和县| 周至县| 云安县| 奈曼旗| 泽库县| 林周县| 建德市| 汉阴县| 婺源县| 奇台县| 原阳县| 修文县| 吐鲁番市| 盐源县| 界首市| 尼玛县|