Js AJAX call code behind Web Method

933人阅读 评论(0) 收藏 举报
分类:

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"
                        }
                };
        }



 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1206216次
    • 积分:21644
    • 等级:
    • 排名:第335名
    • 原创:882篇
    • 转载:88篇
    • 译文:4篇
    • 评论:176条
    个人主页
    最新评论