Saturday, 24 August 2013

I can't retrieve data from a JSON file

I can't retrieve data from a JSON file

I've created a website in wordpress and I'm using wordpress json API to
retrieve data for a web-app I'm developing. The json API is working fine:
http://danielvivancos.com/edu/wordpress/?json=1 I get my Json file. But
now I'm trying to print it in my html page with getjson jquery method.
First I'm just just trying to display in a div some information from the
json file to check that it is working but i don't know why it's not. Here
you can check my script:
$(document).ready(function (){
$("#btn382").click(function(){
$.ajaxSetup({ cache: false });
$.getJSON("http://danielvivancos.com/edu/wordpress/?json=1&count=1",
function(data){
var html = [];
$.each(data.posts.author, function(index, author){
html.push("id : ", author.id, ", ",
"slug : ", author.slug, ", ",
"name : ", author.name, "<br>");
});
$("#div381").html(html.join('')).css("background-color", "orange");
}).error(function(jqXHR, textStatus, errorThrown){ /* assign handler */
/* alert(jqXHR.responseText) */
alert("error occurred!");
});
});
});
And of course I have the #div381 created. I don't know what I'm doing
wrong but I'm really stuck. Any help would be appreciated!!
Edit: The console error is: Cannot read property 'length' of undefined.

No comments:

Post a Comment