【问题标题】:jquery PageMethod saying the method does not existjquery PageMethod 说该方法不存在
【发布时间】:2012-12-01 00:57:19
【问题描述】:

我正在尝试获取这个 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'

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

【问题讨论】:

    标签: jquery asp.net ajax webmethod pagemethods


    【解决方案1】:

    我想用 jQuery 调用页面方法,而不是使用 ScriptManager。请阅读这篇好文章Using jQuery to directly call ASP.NET AJAX page methods

      [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.
       }
    });
    

    【讨论】:

    • 我如何获得 checkRefresh() 返回的布尔值?
    猜你喜欢
    • 2016-12-14
    • 2012-01-24
    • 1970-01-01
    • 2011-11-17
    • 2015-06-16
    • 2016-01-30
    • 1970-01-01
    • 2015-01-26
    相关资源
    最近更新 更多