weixin_33696822 2016-09-22 11:42 采纳率: 0%
浏览 31

Ajax方法无法执行

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/39592576/ajax-function-not-working" dir="ltr">Ajax function not working</a>
                            <span class="question-originals-answer-count">
                                (2 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2016-10-14 15:24:45Z" class="relativetime">3 years ago</span>.</div>
        </div>
    </aside>

enter image description here This Ajax method not calling the webmethod and not update the data to database. I also try it without and with JSON.Strigify but it not work properly. I am using the gridview in that O have take the textboxes and performing the update task on it.
My Javascript Code is -

$("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;
                });

My C# code is-

    [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();
            }
        }
    }
</div>
  • 写回答

1条回答 默认 最新

  • 零零乙 2016-09-22 12:02
    关注

    You don't have dayCode in javascript, but you expect it in C# web method

    {id: ' + id + ',ledger: ' + ledger + ', datafld: "' + datafld + '", aDatafldm: "

    vs

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

    评论

报告相同问题?