我想通过 AJAX 调用来调用服务器方法。但是当我点击按钮并调用 AJAX 函数时,它显示错误。
这是我的代码
<input type="button" id="btn_findsubmit" value="Edit" class="button" />
$(document).on("click", "#btn_findsubmit", function (e) {
var c = $find("<%=cmbobx_search.ClientID %>");
$.ajax({
type: "POST",
url: "schoolregistration.aspx/GetSchoolName",
data: json.stringify({ schoolname: c.get_textboxcontrol().value }),
contenttype: "application/json; charset=utf-8",
datatype: "json",
success: OnSuccessGetSchoolName,
failure: function () {
alert("error! try again...");
}
});
});
[网络方法] [脚本方法]
public static string GetSchoolName(string schoolName){
//Here is the code
}
现在,当我单击按钮时,JavaScript 按钮单击事件正在运行,但 ajax 方法不调用服务器方法 GetSchoolName(我通过 Debug模式知道)。
并抛出一个错误:
ReferenceError: json is not defined
最佳答案
应该是JSON.stringify
,不是json.stringify
关于javascript - 引用错误 : json is not defined when AJAX call the server method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44982898/