ASP.NET:WebMethod:PageMethods.GetRate 不是函数

发布于 2024-09-27 02:44:12 字数 1004 浏览 1 评论 0原文

当我尝试访问 Web 方法时,出现错误:

PageMethods.GetRate is not a function;

我的方法:

    [WebMethod]
    [ScriptMethod]
    public static string GetRate(string date)
    {
        return "qwe123";
    }

注册程序集:

    <%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="aspajax" %>

脚本管理器:

    <aspajax:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

Javascript:

<script type="text/javascript">
    function OnGetRateComplete(result)
    {
        alert(result);
    }

    $(function() { $( "#<%=dtSignDate.ClientID %>" ).datepicker({ onSelect: function(date) { PageMethods.GetRate(date, OnGetRateComplete); }}); });
</script>

GetRate 方法在生成的页面源中可见。

出了什么问题?

When I try to access web method I obtain error:

PageMethods.GetRate is not a function;

My method:

    [WebMethod]
    [ScriptMethod]
    public static string GetRate(string date)
    {
        return "qwe123";
    }

Register assembly:

    <%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="aspajax" %>

Script manager:

    <aspajax:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

Javascript:

<script type="text/javascript">
    function OnGetRateComplete(result)
    {
        alert(result);
    }

    $(function() { $( "#<%=dtSignDate.ClientID %>" ).datepicker({ onSelect: function(date) { PageMethods.GetRate(date, OnGetRateComplete); }}); });
</script>

GetRate method is visible in generated page source.

What is wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百合的盛世恋 2024-10-04 02:44:12

您是否确定已将 ScriptService 属性应用于您的 Web 服务? IE

[ScriptService]
public class WebService : System.Web.Services.WebService

Did you make sure you applied the ScriptService attribute to your web service? i.e.

[ScriptService]
public class WebService : System.Web.Services.WebService
-小熊_ 2024-10-04 02:44:12

好吧,如果你想处理 ajax,那么使用 $.ajax() 是一种请求 WebMethod 的简单好方法。
看看这个问题,你将获得帮助

请求url为[XX.aspx/GetRate],方法:[POST]

well,u want to deal with ajax,then use $.ajax() is a good simple way to request the WebMethod.
take a look at this question, u will get help

request url is [XX.aspx/GetRate], method:[POST]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文