Sudip Bhandari Sudip Bhandari - 4 months ago 18
Javascript Question

Read the json object returned by jsonp api call

This is the api I am calling:
https://api.github.com/search/repositories?q=language:python&sort=stars
which return top starred python projects and displays when triggered via browser.
But when I try to access the json keys from the code it says undefined.
What am I doing wrong?

$.getJSON("https://api.github.com/search/repositories?q=language:python&sort=stars&callback=?", function(result){

alert(typeof(result));
alert(result.total_count);
alert(result.incomplete_results);

});

Answer

Just remove the callback from url:

$.getJSON("https://api.github.com/search/repositories?q=language:python&sort=stars", function(result){

  alert(typeof(result));
  alert(result.total_count);
  alert(result.incomplete_results);

});

Here is a working fiddle: https://jsfiddle.net/a9npgduz/

Comments