终于向Ajax迈出了第一步

前台代码:

    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        function deleteUser(id){
            $.post("UserList.ashx",
            { Id: id },
            function (json) {
                if (json.recode == "1") {
                    alert("删除成功!");
                    //parent.location.reload();此处可以自动刷新页面
                    $("#t"+id).remove();
                } else {
                    alert("删除失败!");
                }
            },
            "json"
            );
        }
    </script>

后台代码:

 

 1         /// <summary>
 2         /// 读取用户列表
 3        /// </summary>
 4        /// <param name="context"></param>
 5         public void ProcessRequest(HttpContext context)
 6         {
 7             context.Response.ContentType = "text/html";
 8 
 9             string id =context.Request.Form["Id"];
10             if (UserInfoManager.DeleteUserInfoById(Convert.ToInt32(id)) > 0)
11             {
12                 context.Response.Write("{\"recode\":\"1\"}");
13             }
14             else
15             {
16                 context.Response.Write("{recode:'2',content:'删除失败'}");
17                 return;
18             }
19         } 

效果图: 

 

 

posted @ 2012-08-12 15:14  江宁织造  阅读(168)  评论(0编辑  收藏  举报