请参阅以下代码:
<script type="text/javascript" src="Javascript/json2.js"></script>
<script type="text/javascript" src="Javascript/jquery-1.11.1.min.js"></script>
<script type = "text/javascript">
function GroupUSNChange() {
alert("got here");
var frm = document.forms[0];
var usn = document.getElementById("ctl00_ContentPlaceHolder1_hfUSN");
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox" && frm.elements[i].name.substr(0, 38) == "ctl00$ContentPlaceHolder1$RematchGroup") {
if (frm.elements[i].checked == true) {
var id = frm.elements[i].name.split("|");
alert(id[1]);
alert(id[2]);
alert(usn.value);
$.ajax({
type: "POST",
url: "frmPNList.aspx/ChangeGroupOfUSNs",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ strNewUSN: usn, strURNs: id(1), strDatasetName: id(2) }),
dataType: "json",
success: OnSuccess(response),
error: function (xhr, errorType, exception) {
var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText
alert("there was an error changing USNs: " + errorMessage);
},
failure: function (response) {
alert('there was a problem changing USNs.')
}
});
function OnSuccess() {
return function (response) {
//alert('got here 2')
alert('Successfully changed USNs')
}
}
}
}
}
}
</script>
和背后的代码:
<System.Web.Services.WebMethod()> _
Public Shared Function ChangeGroupOfUSNs(ByVal strNewUSN As String, ByVal strURNs As String, ByVal strDatasetName As String) As String
Dim intUSN As Integer = CInt(strNewUSN)
Return "done"
End Function
错误出现在开头的行上:$.ajax({
id和USN包含正确的值。为什么我会收到此错误?
答案 0 :(得分:5)
你要求成功的处理程序:
success: OnSuccess(response),
^^^^^^^^^^
什么时候应该更像:
success: function(data) { OnSuccess(data); }