views:

487

answers:

2

Hi All,

I am try to bind the dropdowmlist using jquery. But is showing some error.

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']));
                          });
                      }
                  });

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

Error:

$("#ddlCategory").append($("").val(this['ID']).html(this['Category'])); Microsoft JScript runtime error: Object doesn't support this property or method

Geetha

A: 

Geetha: It looks like data.d is returning an array which contains objects?

Try implementing success like this:

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

did last answer work?