1
Je suis en train d'appeler la méthode asp de jquery utilisant ajax mais j'obtiens l'erreur méthode web inconnue nom de la méthode Parmeterincapable d'appeler la méthode Web en utilisant ajax asp.net jquery
Default.aspx: Code 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
Default.aspx.cs
[System.Web.Services.WebMethod]
public static void UpdateReportStream(string category)
{
//do something
}
sur l'exécution du code objet je reçois l'objet aussi, si j'imprime console.log (msg) en chrome ci-dessous rESU lt Je reçois
"<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& completedSynchronously) +75
</pre></code>
</td>
</tr>
</table>
<br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> 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)
-->"