我有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已過時 –