【问题标题】:Using jquery to use ajax, POST, json. I get success but POST does not appear to run使用 jquery 使用 ajax、POST、json。我成功了,但 POST 似乎没有运行
【发布时间】:2017-03-23 15:32:11
【问题描述】:

我收到了成功警报,但更新日期的功能没有运行。我错过了什么。这是我第一次尝试这个。收购日期和被告 ID 都有值。

这是aspx页面上的代码:

<script type="text/javascript">

    $(function () {
        $("[id*=textboxAcquiredDate]").change(function () {
            var AcquiredDate = $(this).val();
            var DefendantID = $(this).attr("DefendantID");

                $.ajax({
                    type: "POST",
                    url: "Defendants.aspx/acquireddate_update",
                    data: "{'DefendantID' : '" + DefendantID + "', 'AcquiredDate' : '" + AcquiredDate + "'}",
                    contentType: "application/json;charset=utf-8",
                    dataType: "json",
                    error: function (response) {
                        alert("error.");
                    },
                    success: function (response) {
                        alert("update successful.");
                    }
                });
            return false;
        });
    });

</script>

这是aspx.vb文件中的代码(这个函数没有运行):

<WebMethod()>
<ScriptMethod()>
Public Shared Sub acquireddate_update(DefendantID, AcquiredDate)

    Dim stringCommand As String = "UPDATE dbo.Defendant SET AcquiredDate=@AcquiredDate WHERE DefendantID=@DefendantID;"
    Using con As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("connectionstringdev").ConnectionString)
        Dim cmd As New SqlCommand(stringCommand, con)
        cmd.CommandType = Data.CommandType.Text
        With cmd.Parameters
            .AddWithValue("@DefendantID", DefendantID)
            .AddWithValue("@AcquiredDate", AcquiredDate)
        End With
        con.Open()
        cmd.ExecuteNonQuery()
    End Using

End Sub

【问题讨论】:

  • 在 webmethod 中打断,看看它是否在调试中被命中
  • 我试过了。我在调试中没有遇到任何问题。
  • 不能与 POST 一起使用
  • 你是说我应该删除
  • 我从 aspsn-ps 的示例中模拟了这段代码:aspsnippets.com/Articles/…

标签: jquery asp.net json ajax


【解决方案1】:

在 RouteConfig.vb 文件中我注释掉了这一行:

settings.AutoRedirectMode = RedirectMode.Permanent

现在它正在工作!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 2011-04-04
    相关资源
    最近更新 更多