gpt4 book ai didi

jquery PageMethod 说该方法不存在

转载 作者:行者123 更新时间:2023-12-01 03:45:31 28 4
gpt4 key购买 nike

我正在尝试获取此 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 调用页面方法。请阅读这篇好文章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 说该方法不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854712/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com