I am trying to pull a set of cells from a google spreadsheet into a webpage for reporting. I read a few other posts which suggested using a timeout but I cannot seem to get that working either. If you think that would work, I can add my code that I tried to use for the timeout. Here is my code:
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);
}
When I call the function in the main body of the code this is what it looks like:
for(var a=0;a<days.length;a++){
getValue(days[a],dayOfWeek[a]);
}
When I run it in a for loop I get the same value for each of my id tags. They are all the value from the last item in the array. I am not sure if the issue is with the xmlhttprequest not getting enough time or what, any help would be appreciated.
ayet you referenceiin the body? Also you should really consider making a single request for data pertaining to each day rather than 7 concurrently as this will inevitably be the start of a bottleneck when you do get your code working.