我有一个带有静态页面方法的 asp.net 应用程序。我正在使用以下代码调用该方法并获取其返回值。
$.ajax({
type: "POST",
url: "myPage/myMethod",
data: "{'parameter':'paramValue'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {alert(result);}
});
我返回的是[object Object]。
下面是我的静态方法。我的 ScriptManager 中也有 EnablePageMethods="true"
EnablePartialRendering="true"
。
[WebMethod]
[ScriptMethod]
public static string myMethod(string parameter)
{
return "Result";
}
有没有办法获取返回值?
最佳答案
尝试使用 Chrome 开发者工具或 Firfox 的 firebug 插件。不确定 IE 的开发人员工具是否允许您检查 ajax 调用?
您要查找的结果字符串实际上在结果对象中。您需要查看 d 变量。我记得在某处读过为什么会这样,我认为这是 ASP.NET 在玩:|
尝试:
success: function(data) {alert(data.d);}
c#
[WebMethod]
public static string GetTest(string var1)
{
return "Result";
}
希望这对您有所帮助。
关于c# - jquery ajax调用返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6463028/