What the heck am I doing wrong here?
I get this error: [ArgumentException: Unknown web method Test2. 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
<script type="text/javascript" src="/Library/JS/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function () {
$.ajax({
type: "POST",
url: "_debug.aspx/Test2",
data: "{ param: 555 }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
console.log(msg);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}, 1000);
});
</script>
Imports System.Web.Services
Imports System.Web.Script.Services
Partial Class debug
Inherits Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
End If
End Sub
<WebMethod(EnableSession:=True)> _
<ScriptMethod(UseHttpGet:=True)> _
Public Function Test(ByVal param As String) As String
Return "testing " & HttpContext.Current.Session("UserID")
End Function
<WebMethod(EnableSession:=True)> _
<ScriptMethod()> _
Public Function Test2(ByVal param As String) As String
Return "testing " & HttpContext.Current.Session("UserID")
End Function
End Class
The methods need to be Shared:
<WebMethod(EnableSession:=True)> _
<ScriptMethod(UseHttpGet:=True)> _
Public Shared Function Test(ByVal param As String) As String
Return "testing " & HttpContext.Current.Session("UserID")
End Function
<WebMethod(EnableSession:=True)> _
<ScriptMethod()> _
Public Shared Function Test2(ByVal param As String) As String
Return "testing " & HttpContext.Current.Session("UserID")
End Function
and also check your script manager allows page methods:
<asp:ScriptManager ID="ScriptManager1"
EnablePageMethods="true"
runat="server" />