您的位置: 首页 >日志>前端技术>详细内容

前端技术

简单的数据接口调用显示

来源:本站原创 发布时间:2018-05-31 17:43:00 浏览次数: 【字体:

项目中涉及到外部数据的显示,往往都是通过接口来实现的,下面以简单的列子简要的阐述一下怎么通过前端来实现接口数据的调用:

一、接口返回数据(json数据)

  1.     "name": "电视剧", 
  2.     "data": [ 
  3.         { 
  4.             "title": "忘忧酒馆", 
  5.             "href": "", 
  6.             "url": "" 
  7.         }, 
  8.         { 
  9.             "title": "九丹", 
  10.             "href": "", 
  11.             "url": "" 
  12.         }, 
  13.         { 
  14.             "title": "上海女子图鉴", 
  15.             "href": "", 
  16.             "url": "" 
  17.         }, 
  18.         { 
  19.             "title": "楼外楼", 
  20.             "href": "", 
  21.             "url": "" 
  22.         }, 
  23.         { 
  24.             "title": "哦!我的皇帝陛下", 
  25.             "href": "", 
  26.             "url": "" 
  27.         } 
  28.     ] 

二、前端HTML代码

  1.  
  2.  
  3.  
  4. "UTF-8"
  5. 获取数据 
  6. "text/javascript" src="jquery.js"
  7. "text/css"
  8. * { 
  9.     padding:0px; 
  10.     marign:0px; 
  11. ul, li { 
  12.     list-style: none; 
  13. body { 
  14.     min-width:1200px; 
  15.     color: #333; 
  16.     font-size: 14px; 
  17.     font-family:"Microsoft YaHei"
  18.     text-align: center; 
  19.     background-color:#ededed; 
  20. a { 
  21.     color: #333; 
  22.     text-decoration: none; 
  23.     outline: none; 
  24. a:hover { 
  25.     color: #e00; 
  26. #box { 
  27.     width: 660px; 
  28.     margin: 0 auto; 
  29. #box li { 
  30.     width:180px; 
  31.     height:300px; 
  32.     float:left; 
  33.     margin-left:10px; 
  34.     margin-right:10px; 
  35.     background-color:#fff; 
  36.     padding:10px; 
  37.     line-height:30px; 
  38.     margin-bottom:20px; 
  39. #box li .pic a { 
  40.     height:235px; 
  41.     overflow:hidden; 
  42.     display:block; 
  43. #box li img { 
  44.     width: 100%; 
  45.     max-width:100%; 
  46.  
  47.  
  48.  
  49.  
  50. "box"
  51.   
       
    •  
    •  
    •  

    三、输出结果

    ×

    用户登录