jquery PageMethod说该方法不存在

我想获得这个asp.net函数的值:

[ScriptMethod, WebMethod] public static bool checkRefresh() { return isChanging; } 

通过使用PageMethod在jquery中调用它:

 var isAllowed = false; $("#edit").click(function () { PageMethods.editFunc(); PageMethods.checkRefresh(DisplayMyResult); //this line gives the error, though it's probably because it's first. }); function DisplayMyResult(ResultString) { isAllowed = ResultString; if (isAllowed == true || isAllowed == "true") { location.reload(); } else { PageMethods.checkRefresh(DisplayMyResult); } } 

我得到的错误(在chrome控制台中)是

 Uncaught TypeError: Object function () { PageMethods.initializeBase(this); this._timeout = 0; this._userContext = null; this._succeeded = null; this._failed = null; } has no method 'checkRefresh' 

我不知道为什么它不起作用,有人可以帮忙吗?

而不是使用ScriptManager我想用jQuery调用页面方法。 请仔细阅读这篇好文章使用jQuery直接调用ASP.NET AJAX页面方法

  [WebMethod] public static string checkRefresh() { return isChanging; } $.ajax({ type: "POST", url: "PageName.aspx/checkRefresh", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { // Do something interesting here. } });