문제

I am new to API calls. I have to use yahoo geoplanet API. I want to append all country list inside one select box. This is my select list

<select id="Country"></select>

and this is my id link

var country = 'http://where.yahooapis.com/v1/countries?appid=w1u_hHfV34HRdninyHHdnigDEeGV9x4PnbnsKOw4';

how should i do? thanks in advance.

도움이 되었습니까?

해결책

You can use jQuery.getJSON and append &output=json to get the data in JSON format.

Then, you can easily parse the returned data as follow:

$.getJSON('http://where.yahooapis.com/v1/countries?appid=w1u_hHfV34HRdninyHHdnigDEeGV9x4PnbnsKOw4&output=json', function (data) {
        for(var i in data.places.place){
            $('#Country').append('<option value="'+data.places.place[i]['woeid']+'">'+data.places.place[i]['name']+'</option>')
        }
});

working demo

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top