Fill HTML dropdown box with external JSON file data

后端 未结 4 544
甜味超标
甜味超标 2021-01-27 21:28

I am trying to fill a HTML Dropdown menu with data from an external JSON file, which contains the following

{
    \"Destinations\": [
    {
        \"destinatio         


        
4条回答
  •  庸人自扰
    2021-01-27 21:43

    Try this code :

    $.getJSON('yourfile.json', function(data) {
        destinations = data['Destinations']
    
        $.each(destinations, function(id, destination) {
            destination = destination["destinationName"]
            alert(destination)
        })
    });
    

    It allows you to get the destination value in the destination variable, for, after, can do everything with values of this variable.

提交回复
热议问题