jquery+ajax+asp.net简例

客户端:

$.ajax(
                        {
                            type: "POST",
                            url: "SaveRole.aspx?oid=" + $("#hdOperatorId").val() + "&role=" + role,
                            data: "formData1=1&formData2=2",

    //async: false, 同步

                            success: function(mes) {
                                if (mes != "") {

                                    if (mes == "fail") {
                                        //保持失败

                                    } else {
                                        //保存成功
                                        alert("保持成功");
                                        window.location.href = "OperatorList.aspx";
                                    }

                                } else {
                                    //$("#divResult").text("程序出错,请重新启动");
                                }
                            },
                            error: function() {
                                alert("error");
                            }
                        });

 

 

------------------------------

服务器:

 

 protected void Page_Load(object sender, EventArgs e)
        {
            string OperatorId = Request.QueryString["oid"];
            string role = Request.QueryString["role"];

            string formData1=Request.Form["formData1"];

            string formData2=Request.Form["formData2"];


            int ret = 0;
            if (string.IsNullOrEmpty(role))
            {
                ret = ServiceFactory.OperatorService.SetRole(long.Parse(OperatorId), "");
            }
            else
            {
                string[] arr = role.Split(new char[] { ',' });

                System.Text.StringBuilder sb = new System.Text.StringBuilder("");
                for (int i = 0; i < arr.Length; i++)
                {
                    if (!string.IsNullOrEmpty(arr[i]))
                        sb.AppendFormat("<cus OperatorId=\"{0}\" RoleId=\"{1}\"/>", OperatorId, arr[i]);
                }

                ret = ServiceFactory.OperatorService.SetRole(long.Parse(OperatorId), sb.ToString());
            }
            if (ret >= 0)
                Response.Write("success");
            else
                Response.Write("fail");


            Response.End();
        }

 

posted on 2011-07-08 20:02  上校  阅读(375)  评论(0编辑  收藏  举报