skip to Main Content

i have this web service methode

List<object[]> List1 = new List<object[]>();
        [WebMethod(EnableSession = true)]
        [System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
        public List<object[]> GetData(int ID)
        {
            var team = db.TEST.WHERE(a => a.id == ID).ToList();
            List1.Add(new object[]
                            {
                                team
                            });
            return teamList;
        }

and this my Function using Javascript & jQuer & Json

function BindList(id) {
            $.ajax({
                url: "/WebService1.asmx/GetData",
                type: "GET",
                dataType: "json",
                contentType: "application/Json; Charset= Utf-8",
                success: function (data) {
                    var list = "";
                    $.each(data.d[0][0], function (index, item) {
                        list += "<li class='text-secondary p-1'><a class='btn-link text-secondary'><b>" + item.Id+ "</b>" + ", " + "<span class='font-italic'><small>" + item.Name + "</small></span><small><a href='#' Onclick='Delete(" + item.Name + ")'> <i class='float-right far fa-trash-alt'></i></a></small></a>" + "</li>";
                    });
                    $("#list").html(list);// and this to print data to this list id 
                },
                error: function (response) {
                    alert(response);
                }
            });
        }

and this my button to get data

<input id="Button1" type="button" onclick="BindMembersList(1)" value="button" />

My problem is where i need to put the id for give just data have id equal 1
thank you

2

Answers


  1. Try this url:

    url: "/WebService1.asmx/GetData?id="+id
    
    Login or Signup to reply.
  2. Since it’s an url you are calling, pass it on the url of your AJAX call like so:

    function BindList(id) {
            $.ajax({
                url: "/WebService1.asmx/GetData/" + id,
                type: "GET",
                dataType: "json",
                contentType: "application/Json; Charset= Utf-8",
                success: function (data) {
                    var list = "";
                    $.each(data.d[0][0], function (index, item) {
                        list += "<li class='text-secondary p-1'><a class='btn-link text-secondary'><b>" + item.Id+ "</b>" + ", " + "<span class='font-italic'><small>" + item.Name + "</small></span><small><a href='#' Onclick='Delete(" + item.Name + ")'> <i class='float-right far fa-trash-alt'></i></a></small></a>" + "</li>";
                    });
                    $("#list").html(list);// and this to print data to this list id 
                },
                error: function (response) {
                    alert(response);
                }
            });
        }
    

    If it’s not working or you need to pass more parameter to the action, you can specify them and using the "&" as separator like so:

    url: "/WebService1.asmx/GetData?id=" + id + "&parameter2=" + param,
    

    Anyway, your c# method is wrong since you are returning teamList, which is not implemented inside the action

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search