Ajax方法不执行

时间:2016-09-22 11:42:08

标签: c# jquery ajax

enter image description here此Ajax方法不调用web方法而不将数据更新到数据库。我也尝试不使用JSON.Strigify,但它不能正常工作。我正在使用gridview,因为O已经获取文本框并在其上执行更新任务。
我的Javascript代码是 -

$("body").on("click", "[id*=GridView1] .Update", function () {
                    var row = $(this).closest("tr");
                    $("td", row).each(function () {
                        if ($(this).find("input").length > 0) {
                            var span = $(this).find("span");
                            var input = $(this).find("input");
                            span.html(input.val());
                            span.show();
                            input.hide();
                        }
                    });
                    row.find(".Edit").show();
                    row.find(".Delete").show();
                    row.find(".Cancel").hide();
                    $(this).hide();
                    var id = row.find(".ID").find("span").html();
                    var ledger = row.find(".Ledger").find("span").html();
                    var datafld = row.find(".Datafld").find("span").html();
                    var aDatafldm = row.find(".ADatafld").find("span").html();
                    var lType = row.find(".LType").find("span").html();
                    var cType = row.find(".CType").find("span").html();
                    var lAcNo = row.find(".LAcNo").find("span").html();
                    var type = row.find(".Type").find("span").html();
                    var link = row.find(".Link").find("span").html();
                    var tPer = row.find(".TPer").find("span").html();
                    var tCalc = row.find(".TCalc").find("span").html();

                    $.ajax({
                        type: "Post",
                        contentType: "application/json; charset=utf-8",
                        url: "DaybookMast.aspx/UpdateCustomer121",
                        data:JSON.stringify('{id: ' + id + ',ledger: ' + ledger + ', datafld: "' + datafld + '", aDatafldm: "'
                            + aDatafldm + '", lType: "' + lType + '", cType: "' + cType + '", lAcNo: "'
                            + lAcNo + '", type: "' + type + '", link: "' + link + '", tPer: "'
                            + tPer + '", tCalc: "' + tCalc + '" }'),
                        dataType: "json",                    
                        success: function () {
                            if (confirm("Are you sure you want to change !") == true) {
                                alert("Data Updated successfully");
                            } else {
                                alert("You have canceled the changes");
                            }

                        },
                        error: function () {
                            alert("Error while Updating data of :" );
                        }

                    });

                    return false;
                });

我的C#代码是 -

    [WebMethod]
    public static void UpdateCustomer121(int id,string dayCode, string ledger, string datafld, string aDatafldm, string lType, string cType, string lAcNo, string type, string link, string tPer, string tCalc)
    {
       using (SqlConnection con = new SqlConnection(strConnection))
        {
            using (SqlCommand cmd = new SqlCommand("UPDATE DayBookDetails SET DayCode=@DayCode,Ledger = @Ledger,Datafld = @Datafld,ADatafld = @ADatafld,LType = @LType,CType = @CType,LAcNo = @LAcNo,Type = @Type,Link = @Link,TPer = @TPer,TCalc = @TCalc  WHERE ID = @ID"))
            {
                cmd.Parameters.AddWithValue("@ID",id);
                cmd.Parameters.AddWithValue("@DayCode", dayCode);
                cmd.Parameters.AddWithValue("@Ledger", ledger);
                cmd.Parameters.AddWithValue("@Datafld", datafld);
                cmd.Parameters.AddWithValue("@ADatafld", aDatafldm);
                cmd.Parameters.AddWithValue("@LType", lType);
                cmd.Parameters.AddWithValue("@CType", cType);
                cmd.Parameters.AddWithValue("@LAcNo", lAcNo);
                cmd.Parameters.AddWithValue("@Type", type);
                cmd.Parameters.AddWithValue("@Link", link);
                cmd.Parameters.AddWithValue("@TPer", tPer);
                cmd.Parameters.AddWithValue("@TCalc", tCalc);
                cmd.Connection = con;
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

你在javascript中没有dayCode,但你期望它在C#web方法中

  

{id:' + id +',分类帐:' +分类帐+',datafld:"' + datafld +'",   aDatafldm:"

VS

  

int id, string dayCode, string ledger,string datafld,string   aDatafldm,