【发布时间】: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/…