I'm trying to output the "title", "url", "imageUrl" but it only shows "undefined" or "[object Object]", and I have to solve this
My code should output like this:
<p>The Word</p>
<p>Art</p>
<p>Attaining</p>
Here is my JSON code:
{
"ebookList":{
"ebook":[
{
"title":"The Word",
"url":"/products/",
"imageUrl":"/products/",
"_id":"1"
},
{
"title":"Art",
"url":"/products/",
"imageUrl":"/products/",
"_id":"2"
},
{
"title":"Attaining",
"url":"/products/",
"imageUrl":"/products/",
"_id":"3"
}
]
}
}
and my javascript:
function loadBooks() {
$.getJSON('products/books.json', function (result) {
$.each(result, function (i, res) {
alert(res.title);
});
});
}
$.each(result.ebookList.ebook, function (i, res) { alert(res.title); });or$.each(result['ebookList']['ebook'], function (i, res) { alert(res.title); });