나는 조금 혼란 스럽다. 시간 초과/간격이 매 x 초마다 자바 스크립트에서 함수를 만드는 가장 좋은 방법이라는 것을 다른 곳에서 읽었다. 이 API는 내가 사용하고있는 API의 규칙이므로 1 초마다 내 함수가 실행되도록 만들어야합니다. 지저분한 코드의
$.each(match_details_json.result.players, function(index, v){
if (v.account_id == 38440257){ //finds desired playerid
var match_id_2 = matches[i];
hero = v.hero_id;
playerpos = v.player_slot;
var kills = v.kills;
var deaths = v.deaths;
var assists = v.assists;
var kda = ""+kills+"/"+deaths+"/"+assists+"";
console.log(match_id_2, hero, playerpos, result, gamemode, kda);
callback();
console.log(match_id_2, hero, result, gamemode, kda);
h=h+1;
setTimeout(get_match_details(h), 10000);
i=i+1;
}
else{
console.log('Not desired player, skipping...');
}
});
많은이 다음과 같이
내 코드입니다. 그러나 중요한 부분은 setTimeout(get_match_details(h), 10000);
이든 아니든간에 "10 초 후에이 기능을 실행하십시오"라고 말하면서 각 방법이 끝날 때까지 계속 진행합니다. 작동하지 않습니다.
function get_match_details(){
$.ajax({
url: 'php/ApiMatchPull.php',
data: {accountid:'38440257', querytype:'GetMatchDetails', querycondition1:'match_id='+matches[h]},
success: function (data) {
console.log ('Match Details were was pulled successfully');
match_details_json = data;
matchdetailsfill(checkvalidity);
}
});
}
가 사전에 감사합니다
필요한 경우, 여기 내 get_match_details
기능입니다.