Reading a file with xmlhttprequest results in a console error

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;

Everything is going well and I can access the contents of the file from fileArray. BUT, the error appears on the firefox error console, complaining about the contents of line 1 of the file. I do not want the file to be interpreted by javascript or firefox, all I need is content that I parse with javascript.

Firefox console reports

Error: syntax error Source file: file: /// C: /Documents%20and%20Settings/Mike/Desktop/mustache/SBL_PROBES.txt Row: 1, column: 1 Source code: "Name" "Short name" "Long name "" Current "," Maximum "," Minimum "," Daily maximum "," Day Min "

If I put in the file <blockquote> </blockquote>, the errors go away!

What is happening and how can I fix it?

Do I need to do something to close the file? Are things tidied up when these vars go beyond?

+5
source share
1 answer

This should fix:

xmlhttp.overrideMimeType('text/plain');

By default, it seems that local files are parsed using XMLParser.

+13
source

All Articles