2つのURLから$.getJSON()
を使用してJSONを取得し、結果を変数として保存するこのコードはあります。次に、$.when()
とthen()
を使用して、これらの変数からデータを取得します。しかし、これは一度に1つずつ行う場合にのみ動作し、それぞれが$.when()
であり、両方を使用すると動作しません。JQuery.when複数のJSON変数
var player = $.getJSON("http://api.hivemc.com/v1/player/" + $user + "/timv");
var game = $.getJSON("http://api.hivemc.com/v1/game/timv");
$.when(player,game).then(function(maindata, data){
$('#1').text(maindata.total_points);
$('#2').text(maindata.i_points);
$('#3').text(maindata.t_points);
$('#4').text(maindata.d_points);
$('#5').text(maindata.role_points);
$('#6').text(maindata.most_points);
if(maindata.detectivebook == true)
$('#7').text("Yes");
else
$('#7').text("No");
$flare = maindata.active_flareupgrade;
$flare = $flare.charAt(0).toUpperCase() + $flare.slice(1).toLowerCase();
$('#8').text($flare);
$('#9').text(maindata.title);
var d = new Date(maindata.lastlogin * 1000);
var n = d.toISOString();
$('#10').text(d.getDate() + "/" + d.getMonth() + "/" + d.getFullYear());
});
私が手のコンソールエラーは次のとおりです。
jquery-latest.min.js:2 Uncaught TypeError: Cannot read property 'length' of undefined at Function.each (jquery-latest.min.js:2) at Object. (dr:112) at Function.each (jquery-latest.min.js:2) at Object. (dr:108) at Object. (jquery-latest.min.js:2) at j (jquery-latest.min.js:2) at Object.fireWith [as resolveWith] (jquery-latest.min.js:2) at x (jquery-latest.min.js:4) at XMLHttpRequest.b (jquery-latest.min.js:4)`
誰もが私が間違っているのを教えすることはできますか?ありがとう。
は、コンソール内の任意のエラーが発生するのですか? – 31piy
よく私は開発中に私のサイトをホストするために000Webhostを使用していますが、コンソールを表示する方法がわかりません –
ブラウザでF12を押すか、要素を右クリックして「Inspect」をクリックしてください –