Search code examples
jqueryjsonapiyahoo-api

yahoo api county list append to select box


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.


Solution

  • 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