C# 无法使用ajax asp.net jquery调用web方法

C# 无法使用ajax asp.net jquery调用web方法,c#,jquery,asp.net,C#,Jquery,Asp.net,我试图使用ajax从jquery调用asp方法,但我发现了一个错误 未知的web方法参数方法名称 Default.aspx:jquery代码 <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LMSReportingDashboard._Default" %

我试图使用ajax从jquery调用asp方法,但我发现了一个错误 未知的web方法参数方法名称

Default.aspx:jquery代码

 <%@ Page Title="Home Page" Language="C#"
 MasterPageFile="~/Site.master" AutoEventWireup="true"
     CodeBehind="Default.aspx.cs" Inherits="LMSReportingDashboard._Default" %


 <asp:Content ID="SideBar" runat="server"
 ContentPlaceHolderID="SideBar" <asp:ScriptManager ID="scripman1"
 runat="server" EnablePageMethods="True"</asp:ScriptManager

 <ul id="sidebarlist" runat="server"
      <li class="selected"<a href='#'<spanAll</span</a</li
      <li<a href='#'<spanFavourite</span</a</li
      <li<a href='#'<spanBookmark</span</a</li
      <li id="category" <spanCategory</span</li
      </ul </asp:Content

 <asp:Content ID="BodyContent" runat="server"
 ContentPlaceHolderID="MainContent"

 <script type="text/javascript"




     /* Updating lable value depending on selected category */
     $(document).ready(function () {
         $(".left_column ul li").click(function () {
             var control = $(this);
             var selected = $(this).find("span").text();
             $("#stream-title").text(selected);

             /* Calling Page Method */
             $.ajax({
                 'type': 'POST',
                 'url' : 'Default.aspx/UpdateReportStream',
                 'data': '{' + "'category':" + selected + '}',
                 'contentType': "application/json",
                 success: function (msg) {

                 },
                 error: function (msg) {
                     alert(msg);
                 }
             });

         });
     });

     </script

   <header class="report-stream-header"   <h2 id="stream-title"
 class="stream-title"All</h2   </header
      <ul id="report_stream_list" runat="server" class="report_list" 
        </ul    </asp:Content
在执行代码时,我得到object 另外,如果我在chrome中打印console.log(msg),我会得到下面的结果

"<html>
    <head>
        <title>Unknown web method UpdateReportStream.<br>Parameter name: methodName</title>
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Unknown web method UpdateReportStream.<br>Parameter name: methodName</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            <br><br>

            <b> Exception Details: </b>System.ArgumentException: Unknown web method UpdateReportStream.<br>Parameter name: methodName<br><br>

            <b>Source Error:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Stack Trace:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

[ArgumentException: Unknown web method UpdateReportStream.
Parameter name: methodName]
   System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) +540418
   System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +213
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75
</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <hr width=100% size=1 color=silver>

            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1022

            </font>

    </body>
</html>
<!-- 
[ArgumentException]: Unknown web method UpdateReportStream.
Parameter name: methodName
   at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
   at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->"

版本信息:Microsoft.NET Framework版本:4.0.30319;ASP.NET版本:4.0.30319.1022 "
在ajax调用中,尝试JSON.stringify输入参数:

"<html>
    <head>
        <title>Unknown web method UpdateReportStream.<br>Parameter name: methodName</title>
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Unknown web method UpdateReportStream.<br>Parameter name: methodName</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            <br><br>

            <b> Exception Details: </b>System.ArgumentException: Unknown web method UpdateReportStream.<br>Parameter name: methodName<br><br>

            <b>Source Error:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Stack Trace:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

[ArgumentException: Unknown web method UpdateReportStream.
Parameter name: methodName]
   System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) +540418
   System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) +213
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75
</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <hr width=100% size=1 color=silver>

            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1022

            </font>

    </body>
</html>
<!-- 
[ArgumentException]: Unknown web method UpdateReportStream.
Parameter name: methodName
   at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
   at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->"
$.ajax({
     type: 'POST',
     url : 'Default.aspx/UpdateReportStream',
     data: JSON.stringify({category: selected }),
     contentType: 'application/json',
     success: function (msg) {

     },
     error: function (msg) {
     alert(msg);
     }
 });