错误pageMethod未定义 [英] error pageMethod is undefined

查看:118
本文介绍了错误pageMethod未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i get error pageMethod is undefined

我的代码是:



hi i get error pageMethod is undefined
my code is:

script  type="text/javascript">
          function runTest() {
              var ffg = PageMethods.Test();

              alert(ffg);

          }
    </script>





并将其添加到.aspx页面



and add this in .aspx page

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



我的default.cs页面是


my default.cs page is

[System.Web.Services.WebMethod]
        public string Test()
        {
            return "hello";
        }

推荐答案

您的测试方法需要 static



Your Test method needs to be static

[System.Web.Services.WebMethod]
 public static string Test()
 {
     return "hello";
 }


function runTest() {
        PageMethods.Test(OnSucceeded, OnFailed);
    }

    function OnSucceeded(response) {

        alert(response);
    }
    function OnFailed(error) {
        alert(error);
    }







[System.Web.Services.WebMethod]
       public static string Test()
       {
           return "hello";
       }


这篇关于错误pageMethod未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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