JqueryAjax调用一般处理程序的多个方法。

一般来说一个jqueryajax只能调用一个一般处理程序(.ashx),但是有有些时候我们要更高效的使用一般处理程序,需要把一些方法比如增删改查写在一个ashx,方便统一管理。

前台JS:

function searchGuazhang() {
            $.ajax({
                url: "../AjaxHandle/GetGuazhang.ashx",
                type: "post",
                dataType: "json",
                data: "action=SearchGuazhang&name=" + $("#txtguazhangname").val(),
                success: function (data) {
                    $("#tbody").html(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown)
                { alert(textStatus); }
            });
        }

ashx的ProcessRequest方法:

context.Response.ContentType = "text/plain";
            string action = context.Request["action"].ToString();              
            System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(action);
            if (methodInfo != null)
            {
                methodInfo.Invoke(this, new object[] {context});
            }

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">ashx的 </span><span style="font-family: Arial, Helvetica, sans-serif;">SearchGuazhang方法,该方法也是在执行页面回发请求时通过反射获取的方法</span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span><pre name="code" class="csharp">JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            int storeId = Convert.ToInt32(context.Session["storeId"]);
            string name = context.Request.Params["name"];
            DataTable table = incomeBll.SelectGuazhangBywhere(" c_name like '%"+name+"%' and i_sign=0 and storeId=" + storeId);
            string str = "";
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    str += "<tr class=\"tboot1\">" +
                           "<td>" + table.Rows[i]["c_acc"] + "</td>" +
                           "<td>" + table.Rows[i]["c_name"] + "</td>" +
                           //"<td>" + table.Rows[i]["fangjiaType"] + "</td>" +
                           "<td style=\"text-align: center\"><a href=\"#\" id='a" + i + "' οnclick='return guazhang(" + i +
                           ")'>确定</a></td>" +
                           "</tr>";
                }
            }
            else
            {
                str += "<tr class=\"tboot\">" +
                       "<td colspan='4'>该单位不存在!</td>";
            }
            String content = javaScriptSerializer.Serialize(str);
            context.Response.Write(content);


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值