I used the following code to read a file from javascript
var filePath = "SBL_PROBES.txt";
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",filePath,false);
xmlhttp.send(null);
var fileContent = xmlhttp.responseText;
var fileArray = fileContent.split('\n')
var n = fileArray.length;
Things go fine and I can access the file contents from fileArray. BUT an error appears on the firefox error console complaining about the contents of line 1 of the file. I don't want the file interpreted by javascript or firefox, all I want are the contents which I parse with javascript.
The firefox console says
Error: syntax error Source File: file:///C:/Documents%20and%20Settings/Mike/Desktop/mustache/SBL_PROBES.txt Line: 1, Column: 1 Source Code: "title" "Short Name" "Long Name" "Current","Maximum","Minimum","Day Max","Day Min"
If I put <blockquote> </blockquote
> in the file, the errors go away!
What's going on and how can I fix it?
Do I need to do anything to close the file? Will things be cleaned up when these vars go out of scope?
This should fix it:
xmlhttp.overrideMimeType('text/plain');
By default it seems that local files are parsed with the XMLParser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With