Ashx+Jquery(Ajax)案例



jquery端:            

      function GetCredit(credit) {
        $.ajax({
            type: "GET",
            url: "../Ashx/GetCredit.ashx",
            customerID: 'text',
            cache: false,
            data: { customerID: credit },
            success: function (result) {
                $("#<%=hidCredit.ClientID %>").val(result);
                alert("當前可用預存款:" + result + "元");
            }
        })

 

Ashx端:

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string credit = "0";

            if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(context.Request.QueryString["customerID"])))
            {
                string customerID = context.Request.QueryString["customerID"];
                string sql = "select credit from crm_customer where
customer_id=@customerID";
                sql = SqlUtil.setNumber(sql, "@customerID", customerID);
                DataTable dt = SalesCommon.QueryTable(sql);

                if (dt != null && dt.Rows.Count > 0 && !string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(dt.Rows[0]["credit"]))) credit = dt.Rows[0]["credit"].ToString();
            }

            context.Response.Write(credit);
            context.Response.Cache.SetNoStore();
            context.Response.Flush();
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章