Dropdownlist binding using jquery

I am trying to link dropdowmlist using jquery. But some error is displayed.

the code:

                     $.ajax({
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      data: "{product: '" + product + "'}",
                      url: "Search.aspx/FetchCategory",
                      dataType: "json",
                      success: function(data) {
                      $.each(data.d, function() {
                              $("#ddlCategory").append($("<option></option>").val(this['ID']).html(this['Category']));
                          });
                      }
                  });

data values: [{"Category": "All", "ID": "%"}, "Category": "Action" ID ":" 4 "}," Category ":" Race "ID": "5 "}," Category ":" Sports "ID": "6"}]

Error:

.

$ ("# ddlCategory") add (.. $ ("") Val (this is ['ID']) HTML (this is ['Category'])); Microsoft JScript runtime error: object does not support this property or method

Gita

+3
source share
1 answer

: , data.d , ?

:

success: function(data) {
    $.each(data.d[0], function(key,value) {
     $("#ddlCategory").append($("<option></option>").val(key).html(value));
    });
}
+6

Source: https://habr.com/ru/post/1740555/


All Articles