简单的数据接口调用显示
项目中涉及到外部数据的显示,往往都是通过接口来实现的,下面以简单的列子简要的阐述一下怎么通过前端来实现接口数据的调用:
一、接口返回数据(json数据)
- {
- "name": "电视剧",
- "data": [
- {
- "title": "忘忧酒馆",
- "href": "",
- "url": ""
- },
- {
- "title": "九丹",
- "href": "",
- "url": ""
- },
- {
- "title": "上海女子图鉴",
- "href": "",
- "url": ""
- },
- {
- "title": "楼外楼",
- "href": "",
- "url": ""
- },
- {
- "title": "哦!我的皇帝陛下",
- "href": "",
- "url": ""
- }
- ]
- }
二、前端HTML代码
- "UTF-8">
获取数据 - "text/javascript" src="jquery.js">
- "text/css">
- * {
- padding:0px;
- marign:0px;
- }
- ul, li {
- list-style: none;
- }
- body {
- min-width:1200px;
- color: #333;
- font-size: 14px;
- font-family:"Microsoft YaHei";
- text-align: center;
- background-color:#ededed;
- }
- a {
- color: #333;
- text-decoration: none;
- outline: none;
- }
- a:hover {
- color: #e00;
- }
- #box {
- width: 660px;
- margin: 0 auto;
- }
- #box li {
- width:180px;
- height:300px;
- float:left;
- margin-left:10px;
- margin-right:10px;
- background-color:#fff;
- padding:10px;
- line-height:30px;
- margin-bottom:20px;
- }
- #box li .pic a {
- height:235px;
- overflow:hidden;
- display:block;
- }
- #box li img {
- width: 100%;
- max-width:100%;
- }
- "box">
三、输出结果
用户登录
还没有账号?
立即注册