我有一组json数据,这些数据是用php生成的
json_decode
函数,结果如下:
然后我创建一个html文档,并尝试使用jquery调用结果
$.getJSON
:
var apiSrc = 'http://localhost/api/ws-data';
var showData = $('#result');
$(function(){
$.getJSON(apiSrc, function(data) {
console.log(data);
var items = data.blog.map(function (item) {
return item.key + ': ' + item.value;
});
showData.empty();
if(items.length) {
var content = '<li>' + items.join('</li><li>') + '</li>';
var list = $('<ul />').html(content);
showData.append(list);
}
});
showData.text('Loading...');
});
上述结果为:
REST - Get JSON from PHP file on the server side
undefined: undefined
undefined: undefined
undefined: undefined
undefined: undefined
..
它显示了
key
和
value
像
undefined: undefined
剧本出了什么问题?