Jquery JSON不显示数据
我试图学习如何使用JSON,但我已经停留在最基本的。。。 现在我想在ID内容中显示json文件中的数据:author 但是当我单击元素时,它似乎不起作用 脚本:Jquery JSON不显示数据,jquery,json,Jquery,Json,我试图学习如何使用JSON,但我已经停留在最基本的。。。 现在我想在ID内容中显示json文件中的数据:author 但是当我单击元素时,它似乎不起作用 脚本: $(document).ready( function() { $('a').click(function(event) { event.preventDefault(); $.ajax( {
$(document).ready( function()
{
$('a').click(function(event)
{
event.preventDefault();
$.ajax(
{
url: 'Booklist.json',
dataType: 'json',
success: function(data)
{
$.each(data.Booklist, function(index, item)
{
$('#content').append(data.Booklist[0].author);
console.log(item);
});
},
error: function()
{
alert("Houston, we have a problem");
}
});
});
});
JSON:
JSON中的数组称为books,而不是Booklist,因此更改此行:
$.each(data.Booklist, function(index, item)
到
它应该可以工作。看起来还不错,只是在json有一个关键图书的情况下使用Booklist。而且您对Booklist[0]有一个硬引用,而不是使用迭代器项谢谢大家,抱歉,我不得不等待时间限制
$.each(data.Booklist, function(index, item)
$.each(data.books, function(index, item)