jQuery PageMethod说该方法不存在 [英] jquery PageMethod saying the method does not exist

查看:101
本文介绍了jQuery PageMethod说该方法不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取此asp.net函数的值:

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

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

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

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

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

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?

推荐答案

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

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

这篇关于jQuery PageMethod说该方法不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆