This should be very straight forward, but even looking at the other questions, I can’t get it to work.
I’m retrieving some sample world bank data from the following link:
This returns the following JSONP structure:
getWorldBankData([
{
"page": 1,
"pages": 1,
"per_page": "100",
"total": 52
},
[
{
"indicator": {
"id": "DC.DAC.FINL.CD",
"value": "Net bilateral aid flows from DAC donors, Finland (current US$)"
},
"country": {
"id": "GB",
"value": "United Kingdom"
},
"value": null,
"decimal": "0",
"date": "2011"
},
{
"indicator": {
"id": "DC.DAC.FINL.CD",
"value": "Net bilateral aid flows from DAC donors, Finland (current US$)"
},
"country": {
"id": "GB",
"value": "United Kingdom"
},
"value": null,
"decimal": "0",
"date": "2010"
},
I want to get the title of the countries. I had been trying to do so with the following code:
function getWorldBankData(json){
$.each(json.country ,function(){
var country = "<option>"+this.value+"</option>"
$('#category').append(country)
});
}
But I get the following error:
a is undefined
f()jquery.min.js (line 16)
a = undefined
c = function()
d = undefined
getWorldBankData()oil.js (line 11)
json = [Object { page=1, pages=1, per_page="100", more...}, [Object { indicator={...}, country={...}, decimal="0", more...}, Object { indicator={...}, country={...}, decimal="0", more...}, Object { indicator={...}, country={...}, decimal="0", more...}, 49 more...]]
DC.DAC.FINL.CD?per_page=100&date=1960:2012&format=jsonP&prefix=getWorldBankData()DC.DAC...ankData (line 1)
[Break On This Error]
...all(b,0))}}var b=arguments,c=0,d=b.length,e=d,g=d<=1&&a&&f.isFunction(a.promise)...
It doesn’t like this line (line 11):
$.each(json.country ,function(){
What is the correct way to get the country? Thanks.
Haven’t tested it, but something like this should do the trick