JavaScript 使用 XMLHttpRequest 获取 JSON 数据并渲染抽卡记录
const xhr = new XMLHttpRequest(); xhr.open('GET', 'http://127.0.0.1:8080/\u62bd\u5361\u8bb0\u5f55.json'); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { const json = JSON.parse(xhr.responseText); const jsonList = document.getElementById('jsonList'); const jsonLutl = document.getElementById('jsonLutl'); const jsonLurl = document.getElementById('jsonLurl');
json.list.forEach(item => {
const li = document.createElement('li');
li.textContent = `${item.name} - ${item.item_type} - ${item.time}`;
if(item.rank_type=="5"){
li.classList.add("wuxin");
} else if(item.rank_type=="4"){
li.classList.add("sixing");
}
if(item.uigf_gacha_type=="301"){
jsonList.appendChild(li);
} else if(item.uigf_gacha_type=="302"){
jsonLutl.appendChild(li);
} else{
jsonLurl.appendChild(li);
}
});
} }; xhr.send();
原文地址: https://www.cveoy.top/t/topic/qoba 著作权归作者所有。请勿转载和采集!