I am trying to read a file while using google charts. It first read he data from a text file and then create chart using that data. I wrote this code in JS for this purpose
function readTextFile(file){
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false); // using synchronous call
var allText;
alert("Starting to read text");
rawFile.onreadystatechange = function ()
{
alert("I am here");
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
allText = rawFile.responseText;
}
}
}
rawFile.send(null);
alert(allText);
return allText;
}
The problem is : this method is getting called, but the control is not going in
rawFile.onreadystatechange = function ()
{ ... }
Do anyone have any idea regarding this? Thanks in advance!
note: I am sending the file name in the parameter (file). I am not passing the address as both this HTML file and the text file are in the same folder.
update 1: I printed rawFile.readyState , and it always shows 1 which means server connection established. My code is a simple HTML code, not using any server for this purpose.
update 2: I tried adding file:/// before the file name that is not working too :(