Привет, я вызываю простой метод страницы из 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); } );
, он покажет правильный ответ: «Да, это работает». Однако мне нужно передать параметр функции. Я ничего не пропустил?
Спасибо за помощь.