开发者

Help I am stuck trying to parse Json string returned from my webservice

I am not exactly sure if I am getting JQuery or simply a string, even after applying the scriptservice attribute and setting the ResponseFormat property to Json.

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public ArrayList GetRoles()
{
      ArrayList arr = new ArrayList();
      arr.Add("manager");
      arr.Add("Project manager");
      arr.Add("Super Admin");
      arr.Add("Admin");
      arr.Add("Customer Rep");
      arr.Add("Sales Rep");
      arr.Add("Help Desk");
      arr.Add("Supervisor");
      arr.Add("Client");
    return arr;
}

What I get on the front end(when I view it using a popup) is a string of all the value concatenated and separated by commas. The code below does not seem to work to display the list in a dropdownlist. Any help will be appreciated.

 $.each(msg.d, function (i, item) {

                          if (item) {
                                alert(i);
                                alert(item);
                                $("<%= SelectRole.ClientID %>").append($("<option></option>").开发者_运维技巧attr("value", i).text(item));
                          }
                    });


Since its a concatenates string seperated by commas you can try this

$.each(msg.split(","), function (i, item) {
    $("#<%= SelectRole.ClientID %>")
    .append($("<option></option>")
    .attr("value", "-1")
    .text("select role"));

    if (item) {
      alert(item);

      $("#<%= SelectRole.ClientID %>")
      .append($("<option></option>")
      .attr("value",i)
      .text(item));
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜