WebForm使用ajax

来源:互联网 发布:手机版迅雷网络异常 编辑:程序博客网 时间:2024/06/07 05:13

前端:

           function Un_Enable(code)
            {   
                $.ajax({
                    type: 'get',
                    url: 'UserLogOn.aspx',
                    datatype:"json",
                    contentType:"application/json;charset=utf-8",
                    data:{action:'UnEnable',usercode:code},
                    async: true,
                    success: function (result) {
                        alert(result);
                    },
                    error: function () {
                        setContainer('ERROR!');
                    }
                });
            }

后台:

    protected void Page_Load(object sender, EventArgs e)
    {

        string action = Request.QueryString["action"];
        string usercode = Request.QueryString["usercode"];
        if (!string.IsNullOrEmpty(action))
        {
            switch (action)
            {
                case "UnEnable":
                    UnEnable(usercode);
                    break;
            }
        }
    }


    public void  UnEnable(string code)
    {
        string result = "";
        try
        {
            DataBase.DataHelper DHp = new DataBase.DataHelper();
            DHp.ExecCommand("update table set Enable='False' where code='" + code + "'");
            result = "{\"state\":\"1\",\"message\":\"禁用成功!\"}";
        }
        catch (Exception ex)
        {
            result = "{\"state\":\"0\",\"message\":\"禁用失败!原因:" + ex.Message.ToString() + "\"}";
        }
        Response.Write(result);
        Response.End();

    }



0 0
原创粉丝点击