jQueryを使ったAJAX通信でのJSON取得
コード例
// JSONで通信する場合、WebAPI側は クロスサイトスクリプティングへの事前対応が必要
$.ajax({
type: "GET",
url: 'https://WebAPIサーバ名もしくはIPアドレス:ポート/ディレクトリ',
dataType: "json"
})
.done(function(json){
console.log(json);
})
.fail(function(){
console.log("ajax fail");
});
元データ
id | name |
---|---|
1 | taro |
2 | john |
3 | patrick |
4 | pierre |
5 | abele |
6 | wei |
実行結果
[{id: 1, name: "taro"}, {id: 2, name: "john"}, {id: 3, name: "patrick"}, {id: 4, name: "pierre"}, {id: 5, name: "abele"}, {id: 6, name: "wei"}] (6) (localhost, line 90)
関連ページ
ASP.NET Core Minimal API で EntityFramework を使った PostgreSQL Restful API