Js AJAX call code behind Web Method

Js AJAX call web method


Js :

  $.ajax({
        type: "POST",
        url: "CustomerPersonalDetails.aspx/SearchAddress",
        data: "{ 'searchParam': 'abc' }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        success: function (data, status) {
            var obj = eval(data.d);
            var innerHtml = "<table cellspacing='0' id='tbl_address_searchResults'>";

            for (var i = 0; i < obj.length; i++) {
                innerHtml += "<tr><td>" + obj[i].name + "</td>";
                innerHtml += "<td>" + obj[i].desc + "</td>" + "</tr>";
            }
            innerHtml += "</table>";
            $("#" + divId).html(innerHtml);

        },

        failure: function (data) {
            alert(data);
        },
        error: function (data) {
            alert(data);
        }
    });



c# method:


 [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static dynamic SearchAddress(string searchParam)
        {
            return new[]
                {
                    new
                        {
                            name = "aaa",
                            desc = "desc1"
                        }
                };
        }



你可能感兴趣的:(method)