PageMethods使用1参数调用成功,但在2上失败(未知Web方法)

时间:2013-12-10 02:43:16

标签: javascript asp.net json vb.net pagemethods

我已成功使用PageMethods将单个参数发布到代码隐藏的aspx页面,但在尝试提供两个参数(或字符串以外的对象)时会收到错误“未知的Web方法”。

工作代码,在我的aspx页面中:

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

并在包含的js文件中:

function AjaxSuccess(results) {
    alert("AjaxSuccess: " + results);
}
$(document).ready(function () {
    PageMethods.TestAjaxCall("value 1",  AjaxSuccess);
}

并在代码隐藏中:

<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String) As String
    Return item1
End Function

但是,以下更改会导致异常(System.ArgumentException:未知的Web方法TestAjaxCall。): 并在一个包含的js文件中:

function AjaxSuccess(results) {
    alert("AjaxSuccess: " + results);
}
$(document).ready(function () {
    PageMethods.TestAjaxCall("value 1", "value 2", AjaxSuccess);
}

伴随着代码隐藏的变化:

<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String, ByVal item2 As String) As String
    Return item1 & ": " & item2
End Function

1 个答案:

答案 0 :(得分:0)

删除&lt; ScriptMethod&gt;标签做了诀窍:

<WebMethod> _
Public Shared Function TestAjaxCall(ByVal item1 As String, ByVal item2 As String) As String
    Return item1 & ": " & item2
End Function