当我调用JSON加载webmethod静态事件时,那个事件没有加载[我通过调试模式看到]通过单击Asp.net C#中的提交按钮。在整个表单的位置,即整个网页正在加载。但我不想加载整个网页。
这是我的代码
这是客户端代码
<input type="submit" id="btn_save" value="Save" class="button" />
$(function () {
$(document).on("click", "#btn_save", function (e) {
$.ajax({
type: "POST",
url: "schoolregistration.aspx/EntrySave",
data: JSON.stringify({ name: $('#txt_schoolname').val() }),
success: function (msg) {
if (msg.d) {
alert("Successfully Added School Registration...!!!");
return false;
}
},
failure: function () {
alert("Error! Try again...");
}
});
});
});
这是服务器端代码
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static void EntrySave(string schoolName)
{
//here is the code
}