Skip to content
Amal Hashim
All posts
Snippet

jQuery getJSON

Populate a dropdown list from a JSON service using $.getJSON and $.each.

1 min read#JavaScript#jQuery

An example of using $.getJSON to fill a dropdown list.

js
$.getJSON("URL", null,
   function (data) {
      $.each(data.d, function (i, result) {
         var optionText = "<option value='" + result.value + "'>"
            + result.text + "</option>";
         $('#ddlSelectTagId').append(optionText);
      });
   }
);

Replace URL with the address of your service. For each item returned, the code builds an option element and appends it to the select with the id ddlSelectTagId.