开发者

reading file with xmlhttprequest results in error console entry

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 fir开发者_运维问答efox 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜