こんにちは、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" />
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); } );
「はい、これは機能しています」という正しい応答が表示されます。ただし、関数にパラメーターを渡す必要があります。私は何かが恋しいですか?
手伝ってくれてありがとう。