var oTab = document.getElementById("tab"); //保证是title
var tHead = oTab.tHead; //title下获取thead的特有方法
var oThs = tHead.rows[0].cells; //title下获取thead下第一行的所有单元格的特有方法
var tBody = oTab.tBodies[0]; //title下获取第一个tbody的方法
var oRows = tBody.rows; //title下获取tbody下所有行的方法
//-->1首先获取后台data.txt中的数据"JSON格式的字符串"-->Ajax(async javascript and xml)
//1)创建一个Ajax对象
var xhr = new XMLHttpRequest;
//2)打开需要请讲数据的那个文件地址
xhr.open("get", "json/data.txt", true);
//3)监听请求状态
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && /^2\d{2}$/.test(xhr.status)) {
var val = xhr.responseText;
console.log(val);
}
};
//4)发送请求
xhr.send(null);
提示以下错误怎么解决?:Access to XMLHttpRequest at 'file:///C:/Users/Administrator/Desktop/zuoye/%E7%8F%A0%E5%B3%B0%E7%BB%83%E4%B9%A0/vip/%E8%AF%BE%E6%97%B631-36%E5%AE%9E%E6%88%98%E7%AC%91%E5%82%B2%E6%B1%9F%E6%B9%96/json/data.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
相关分类