我有jQuery代码来从服务器获取JSON:jQuery.getJSON呼叫ASP.NET方法
$(document).ready(function() {
$.getJSON('Default2.aspx/GetPerson', { 'firstname': 'brian', 'lastname': 'lee' }, function (response) {
alert(response.Age);
});
});
Default2.aspx代码:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static String GetPerson(String firstname, String lastname)
{
Person p = new Person(firstname, lastname);
return "{\"Age\":\"12\"}";
}
的问题是:
为什么我的脚本没有调用方法GetPerson
?我附加了调试器GetPerson
,但似乎没有调用。
任何帮助将不胜感激!
我不知道如果是这样的原因,你可以给属性名作为数据。 data:{'firstname':'brian','lastname':'lee'} –
不,它不起作用 –
http://stackoverflow.com/questions/16910982/calling-webmethod-returning-ilistt-from- jQuery的阿贾克斯与 - NHibernate的和-MVC。我想你需要摆脱webmethod.as每个这篇文章,webmethods已过时 –