ajax调用实例

function calculateIntegral() {
    var GPrice = document.getElementById("GiftMoeny").value;
    var CPrice = document.getElementById("CodeMoeny").value;
    var freight = document.getElementById("Shopfreight").value;
    $.ajax({
        type: "POST",
        url: "../Controller/UserCart/SubmitOrder.ashx",
        data: { HttpType: "UserJifenDikou", GiftPrice: GPrice, CardPrice: CPrice, Orderfreight: freight },
        cache: false, //设置时候从浏览器中读取 缓存  true 表示 是
        datatype: "json",
        success: function (data, status) {
            if (data != "") {
                data = eval("(" + data + ")");
                $("#IntegralMoeny").attr("value", data.ds[0].IntegralMoeny); //赋值积分抵扣金额
                $("#lblJifenMoney").html(data.ds[0].IntegralMoeny);
            }
            TotalOrder();
        }
    });

}

public void ProcessRequest(HttpContext context)
    {
        string Type = context.Request.Form["HttpType"];

        if (Type == "UserJifenDikou")
        {
            string GiftPrice = context.Request.Form["GiftPrice"];
            string CardPrice = context.Request.Form["CardPrice"];
            string Orderfreight = context.Request.Form["Orderfreight"];

            context.Response.Write(IsIntegralAll(Convert.ToDecimal(GiftPrice), Convert.ToDecimal(CardPrice), Convert.ToDecimal(Orderfreight)));
        }
    }

    public string IsIntegralAll(decimal cartprice, decimal codePrice, decimal Orderfreight)
    {
        string strhtmldate = "";
        ShopCartHelp Help = new ShopCartHelp();
        decimal ShopMeony = Help.GetShopPrice();
        //如果用户可抵扣的金额大于剩余金额
        if (Help.UserIntegralMoeny() >= ShopMeony)
        {
            strhtmldate = "{\"ds\":[{\"IntegralMoeny\":" + ShopMeony + ",\"OrderMoeny\":\"" + Orderfreight + "\"}]}";
        }
        else
        {
            decimal OrderMoeny = 0;// dikouMoney - Help.UserIntegralMoeny();
            strhtmldate = "{\"ds\":[{\"IntegralMoeny\":" + Help.UserIntegralMoeny() + ",\"OrderMoeny\":\"" + OrderMoeny + "\"}]}";
        }
        return strhtmldate;
    }

原文地址:https://www.cnblogs.com/doosmile/p/2304775.html