【发布时间】:2017-04-25 15:46:55
【问题描述】:
问题,为什么以及如何让我的 json api 数据显示。显示我的 api 信息
我是 api 新手,正在尝试
json 数据
[{"title":"One article - API 1 - 2017-04-25 15:43:20"},{"title":"Another article - API 1 - 2017-04-25 15:43:20"},{"title":"Great article - API 1 - 2017-04-25 15:43:20"}]
我有一个小的 js 文件,我用它来获取我的 api
$(document).ready(function () {
$('#get-data').click(function () {
var showData = $('#show-data');
$.getJSON('https://some api ', function (data) {
console.log(data);
var items = data.title (function (item) {
return title;
});
showData.empty();
if (items.length) {
var content = '<li>' + items.join('</li><li>') + '</li>';
var list = $('<ul />').html(content);
showData.append(list);
}
});
showData.text('Loading the JSON file.');
});
});
然后我有一个 html 部分来显示 api 信息 onlick
<body>
<a href="#" id="get-data">Get JSON data</a>
<div id="show-data"></div>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="example.js"></script>
</body>
【问题讨论】:
标签: javascript html json rest api