Sudip Bhandari
Sudip Bhandari

Reputation: 2255

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);

});

Upvotes: 1

Views: 42

Answers (1)

Ricardo Pontual
Ricardo Pontual

Reputation: 3757

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/

Upvotes: 1

Related Questions