jquery PageMethod saying the method does not exist

无人久伴 提交于 2019-12-11 02:57:02

问题


i am trying to get a value of this asp.net function :

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

by calling it in jquery using the PageMethod:

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

the error i get (in the chrome console) is

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

i do not know why is it not working, can anyone help?


回答1:


rather than using ScriptManager I would like to calling the page method with jQuery instead. please go through this nice article 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.
   }
});


来源:https://stackoverflow.com/questions/13854712/jquery-pagemethod-saying-the-method-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!