ASP.net PageMethods return undefined

前端 未结 2 836
花落未央
花落未央 2021-01-24 00:44

Hi everyone i trying to get data from cs to js using ToolkitScriptManager. this is my aspx :

    


        
相关标签:
2条回答
  • 2021-01-24 00:51

    You need to supply a success and a failure callback to the webmethod call as below.

      $(window).load(function () {
                                        PageMethods.isConnected(fnsuccesscallback,fnerrorcallback);
    
            });
            function fnsuccesscallback(data) {
                alert(data);
    
            }
            function fnerrorcallback(result) {
                alert(result.statusText);
            }
    

    Also, there is another way of accessing the page methods using $.ajax.

    <head id="Head1" runat="server">
        <title></title>
        <script src="../assets/lib/jquery/jquery-2.0.3.js" type="text/javascript"></script>
        <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
        <script type="text/javascript" language="javascript">
    
             $(window).load(function () {
    
          $.ajax({
                type: "POST",
                url: "PageMethodTest.aspx/isConnected",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: fnsuccesscallback,
                error:fnerrorcallback
            });
        });            function fnsuccesscallback(data) {
                alert(data.d);
    
            }
            function fnerrorcallback(result) {
                alert(result.statusText);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager EnablePageMethods="true" runat="server">
        </asp:ScriptManager>
        <div>
        </div>
        </form>
    </body>
    
    0 讨论(0)
  • 2021-01-24 01:03

    Will do 100% work

         <script type="text/javascript">
           function Generate()
           {              
               var result = PageMethods.GenerateOTP(your parameter, function (response)
               {
                   alert(response);
               });
           }
    </script>
    
    0 讨论(0)
提交回复
热议问题