我正在尝试将一组单元格从谷歌电子表格中提取到网页中进行报告。我阅读了其他一些建议使用超时的帖子,但我似乎也无法使其正常工作。如果您认为这可行,我可以添加我尝试用于超时的代码。这是我的代码:
var days = new Array();
days[0] ="G11%3AG11"; /*Today*/
days[1] ="G10%3AG10";
days[2] ="G9%3AG9";
days[3] ="G8%3AG8";
days[4] ="G7%3AG7";
days[5] ="G6%3AG6";
days[6] ="G5%3AG5";
days[7] ="G4%3AG4"; /*One week ago*/
var dayOfWeek = new Array();
dayOfWeek[0] ="day0";
dayOfWeek[1] ="day1";
dayOfWeek[2] ="day2";
dayOfWeek[3] ="day3";
dayOfWeek[4] ="day4";
dayOfWeek[5] ="day5";
dayOfWeek[6] ="day6";
dayOfWeek[7] ="day7";
function getValue(cell, element){
var url = "https://docs.google.com/spreadsheet/pub?key=MyKey&single=true&gid=2&range="+cell+"&output=csv";
temp = new XMLHttpRequest();
temp.onreadystatechange = function () {
if (temp.readyState === 4) {
document.getElementById(element).innerHTML = temp.responseText;
}
};
temp.open("GET", url, true);
temp.send(null);
}
当我在代码主体中调用该函数时,它看起来像这样:
for(var a=0;a<days.length;a++){
getValue(days[a],dayOfWeek[a]);
}
当我在 for 循环中运行它时,我的每个 id 标签都会得到相同的值。它们都是数组中最后一项的值。我不确定问题是否与 xmlhttprequest 没有足够的时间或什么有关,任何帮助将不胜感激。