私は、サーバからJSONを取得するjQueryのコードを持っている: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
にデバッガを付けますが、呼び出されていないようです。
助けていただければ幸いです!
私はそれが理由であれば、あなたがデータとしてプロパティ名を与えることができることを確認していません。データ:{'ファーストネーム': 'ブライアン'、 'ラストネーム': 'リー'} –
いいえ、それは動作しません –
http://stackoverflow.com/questions/16910982/calling-webmethod-returning-ilistt-from- jquery-ajax-with-nhibernate-and-mvc。私はあなたがこの投稿ごとにwebmethod.asを取り除く必要があると思う、webmethodsは廃止されました –