1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個贊
如果您希望根據(jù)狀態(tài)在最后階段執(zhí)行不同的操作,則需要嵌套if語句。首先if檢測最后階段,然后測試狀態(tài)。
this.refreshLyric = function(currentSong, currentArtist) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
var data = JSON.parse(this.responseText);
var openLyric = document.getElementsByClassName('lyrics')[0];
if (data.type === 'exact' || data.type === 'aprox') {
var lyric = data.mus[0].text;
document.getElementById('lyric').innerHTML = lyric.replace(/\n/g, '<br />');
//debugging
console.log("Success Lyric found");
} else {
//debugging
console.log("Lyric not found");
}
} else {
// go to another function
var page = new Page();
page.refreshLyric2(currentSong, currentArtist);
}
}
}
xhttp.open('GET', 'https://api.vagalume.com.br/search.php?apikey=' + API_KEY + '&art=' + currentArtist + '&mus=' + currentSong.toLowerCase(), true);
xhttp.send()
}
添加回答
舉報(bào)