function useRealData() { const xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener('readystatechange', function () { if (this.readyState === this.DONE) { const re = JSON.parse(this.responseText).data for (let i = 0; i < re.length; i++) { const basic_tool_type = re[i].basic_tool_type const basic_tool_id = re[i].basic_tool_id const platform_name = re[i].platform_name const danger_level = re[i].danger_level const user_name = re[i].user_name const user_password = re[i].user_password const remark = re[i].remark const trEle = document.createElement("tr") const tableEle = document.getElementById("table") trEle.innerHTML = ` ${basic_tool_type} ${basic_tool_id} ${platform_name} ${danger_level} ${user_name} ${user_password} ${remark} ` switch (danger_level) { case "1": trEle.style.backgroundColor = "rgba(226, 208, 43, 0.5)" break; case "2": trEle.style.backgroundColor = "rgba(226, 43, 43, 0.5)" default: break; } tableEle.appendChild(trEle) } } }); xhr.open('GET', `http://${SERVER_IP}:${SERVER_PORT}/api/user`); xhr.send(); }