###前提・実現したいこと
以下サイトにあるASP.NET(c#)で作成したAzure上のAPIをAndroidスマートフォンで受け取りたいです。
https://channel9.msdn.com/Events/de-code/decode-2015/DEV-011
動画と異なる点は、受け取り側のスマフォアプリは、html css javascriptで画面表示するネイティブアプリ仕様です。
###発生している問題・エラーメッセージ
デバッグしましたが、アプリ上のhtmlにERRORとして表示されませんでした。
拡大表示
###該当のソースコード
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>10</title> </head> <body> <table id="a" border=1> <tr> <th>version</th> <th>codename</th> </tr> </table> <table id="b" border=1> <tr> <th>version</th> <th>codename</th> </tr> </table> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $.ajax({ url: 'http://decode2017iq155webapi*****************************************', dataType: 'jsonp', jsonpCallback: 'android' }).done(function(json) { for(var i=0; i<json.length; i++) { $('#b').append(json[i].au_fname + ' ' + json[i].au_lname + '<br>'); } }).fail(function() { $('#b').text('ERROR'); }); (function() { //Ajax $.get({ url: 'http://decode2017iq155webapi***************************', }, function(data){ $('#b').html(data.au_fname + ' ' + data.au_lname); }); })(); </script> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Http; using Decode2017iq155WebInterfaces.thingB.ListAuthors; using Decode2017iq155WebApi.Models; //作成順序⑥→作成順序⑦発行 namespace Decode2017iq155WebApi.Controllers.thingB { [Route("thingB/ListAuthors/{Action}")] public class ListAuthorsWebApiController : ApiController { [HttpGet] public List<AuthorDTO> GetAllAuthors() { using (pubsEntities pubs = new pubsEntities()) { var query = from a in pubs.authors select new AuthorDTO { AuthorID = (int)a.au_id, AuthorName = a.au_fname + " " + a.au_lname }; return query.ToList(); } } } }
###試したこと
ブラウザで表示できるか確認したところ同様の表示でした。
ただ、WEBAPIを叩いただけなのであれば、画面表示は、IEを利用するとJSONのような表記で、chromeで受け取るとxmlのような表記でした。
目的は、動画で作られるWEBAPIをHTMLとjavascriptで表のように表示したいのですが、うまくいきません。
何か助言頂けないでしょうか。よろしくお願い致します。
###追記1月13日21:15
FiddlerにてAPI叩いた結果
[{"AuthorID":1,"AuthorName":"Kenji Takahashi "},{"AuthorID":2,"AuthorName":"Tarou Satoh "},{"AuthorID":3,"AuthorName":"Hanako Suzuki "}]
###1月13日23時14分追記
html
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="UTF-8"> 5 <title>10</title> 6</head> 7<body> 8 <table id="b" border=1> 9 <tr> 10 <th>version</th> 11 <th>codename</th> 12 </tr> 13 </table> 14 15 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 16 <script> 17 18 (function() { 19 //Ajax 20 $.get({ 21 url: 'http://decode2017iq155webapi***************************', 22 }, function(data){ 23 $('#b').html(data.au_fname + ' ' + data.au_lname); 24 }); 25 })(); 26 </script> 27</body> 28</html>
回答1件
あなたの回答
tips
プレビュー