2016-04-26 21 views
-1

ウェブページで再生された最後の10曲を表示します。ここでは私が使用しているコードがありますが、jsonファイルから要求された情報を取得して表示することができません。 https://jsfiddle.net/Heropiggy95/6qkv7z3b/誰かがエラーを指摘したり、実例を示すことができますか?ありがとうございました。ウェブページのjsonデータを解析するのに役立つ必要があります

$(document).ready(function() { 
    $.getJSON("http://apps.radioactive.sg/lastsongsplayed.php?stationId=995fm&callback=myfunction", function(data) { 
    var html = ''; // declare the variable that will be used to store the information 
    $.each(data.myfunction, function(i, item) { 
     { 
     html += 'Song: ' + item.song.track + ', Artist: ' + item.song.artist + ', Time: ' + item.playedtime + ''; 
     } // 
    }); // 
    $('.nowplaying').append(html); // print the information to the document with a span class of 'nowplaying' and use the jQuery append method to insert the information. 
    }); // close JSON call 
}); // close document ready function 
+0

ようJSON.parseをそのない使用してみてください。詳細を記入してください。 – C4u

答えて

0

おそらくあなたが提供することができます最悪infoですworking` `この

$(document).ready(function() { 
    $.getJSON("http://apps.radioactive.sg/lastsongsplayed.php?stationId=995fm", function(data) { 
    var html = ''; // declare the variable that will be used to store the information 
    var parsedData = JSON.parse(data); 

    $.each(parsedData, function(i, item) { 
     { 
     html += 'Song: ' + item.song.track + ', Artist: ' + item.song.artist + ', Time: ' + item.playedtime + ''; 
     } // 
    }); // 
    $('.nowplaying').append(html); // print the information to the document with a span class of 'nowplaying' and use the jQuery append method to insert the information. 
    }); // close JSON call 
}); // close document ready function 
+0

ここでは私が取り組んできたコードはありますが、出力を生成できないようです。 https://jsfiddle.net/Heropiggy95/6qkv7z3b/問題を解決するためにどのようなステップを取るべきか分かりません。このページのトラブルシューティング方法についてアドバイスできますか?ありがとうございました。 – HeroPiggy95

+0

このコードをlocalhostまたは他のドメインで実行しようとしていますが、ローカルで実行しようとしました。< 要求されたリソースに 'Access-Control-Allow-Origin'ヘッダーがありません。したがって、Origin 'http://fiddle.jshell.net'はアクセスが許可されていません。 ドメインでajaxリクエストを送信できるようにするには、これをサーバーで処理する必要があります。 –

+0

localhostで実行しようとしています。私は研究を行いました。これは、jsonpでajaxを使用することで 'Access-Control-Allow-Origin'をバイパスできることを示しています。 http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonpこのメソッドを使用してサーバーから情報を取得することは可能ですか? – HeroPiggy95

関連する問題