Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I cant read the json file date to populate the dynamic dropdown list

What I have tried:

HTML:
    <p>
          <label for="people">People: </label>
           <select id="people" ></select>
            </p>

          <script type="text/JavaScript">

       $select = $('#people');

         $.ajax({
        url:   "http://localhost:58421/jsonfiles/person.json",
        dataType: 'JSON',
        success: function (data) {
           alert("data");
          $select.html('');
           $.each(data.person, function(key, val){
           $select.append('<option id="' + val.id + '">' + val.name + '</option>');
            })
            },
           error: function () {
           $select.html('<option id="-1">none available</option>');
               }
             });
           </script>

person.json:
person": [
  {
    "id": "1",
    "name": "Person1"
  },
  {
    "id": "2",
    "name": "Person2"
  },
  {
    "id": "3",
    "name": "Person3"
  }
]}
Posted
Comments
Dennis E White 23-Aug-18 10:08am    
have you even tried to google this yourself?? I did a quick google and came up with several examples.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900