你好,我正在从JavaScript调用一个简单的页面方法,这是我的标记代码:
function OnCallSumComplete(result, userContext, methodName) {
alert(result);
}
function OnCallSumError(error, userContext, methodName) {
if (error !== null) {
alert(error.get_message());
}
}
function test(){
var contextArray = "";
PageMethods.TestMethod("test parameter", OnCallSumComplete, OnCallSumError, contextArray);
}
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
at cs
[System.Web.Services.WebMethod]
public static string TestMethod(string para)
{
return "Yes this is working";
}
警报显示结果并说“null”。我检查了Firebug,没有从控制台看到错误。
如果我将TestMethod更改为
[System.Web.Services.WebMethod]
public static string TestMethod()
{
return "Yes this is working";
}
并且PageMethod
PageMethods.TestMethod( function (response) { alert(response); } );
它显示了正确的响应为“Yes this is working”。然而,我需要向函数传递参数。我有什么遗漏吗?
感谢您的帮助。