名前にIDの名前のついたツイッチチャンネルがあり、結果が得られない場合は、正しいステータスをチャンネルに帰属させて「オフライン」にしたいと思っています。どのチャンネルがどのステータスがかなりランダムであるかを除いて、すべて正常に動作します。ほとんどの場合、最後のものが影響を受ける唯一のものです。 .ajaxに一度に1つのリクエストを行うにはどうすればよいですか? (私はすでにasync:falseを入れてみました)ajax関数でリクエストを1つずつ処理するにはどうすればよいですか?
$(document).ready(function() {
var names = [];
var status = 'Offline';
var iconColor = "#B00";
$('.channel').each(function(index) {
names.push($(this).attr('id'));
});
$(".channel").each(function(index) {
iconColor = "#B00";
$(this).html('<div class="iconStatus col-md-1"><i class="fa fa-television" aria-hidden="true"></i></div><a href="https://www.twitch.tv/' + names[index] + '"><div class="nameChannel col-md-3"></div></a><div class="status col-md-8">Offline</div>');
$(this).children("a").children(".nameChannel").text(names[index]);
$.ajax({
url: 'https://wind-bow.glitch.me/twitch-api/streams/' + names[index],
dataType: 'jsonp',
type: 'GET',
async: false,
jsonpCallback: 'JSON_CALLBACK',
success: function(data) {
if (data.stream !== null) {
assignProps(names[index], data.stream.channel.status, '#0B0');
}
}
});
});
});
function assignProps(name, status, iconColor) {
$('#' + name).children('.status').text(status);
$('#' + name).children('.iconStatus').children('i').css('color', iconColor);
};
あなたが実際に戻って、すべてのデータを取得していることを確認するために、データオブジェクトをログに記録しようとしたのですか?それは何を言いますか? – mnemosdev
はい、私は各オブジェクトを取得しています – stkro
ランダムな順序で – stkro