Reputation: 3619
i'm trying to read in a local file in javascript, I am not publishing this online so I only need it to work with my broweser (Firefox), i am currently trying to parse it using an XML Http request:
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "file://Users/spe_eddy_gonzalez/Dropbox/Me/Hon Proj/Wikipedia/simplewikitext.txt", true);
txtFile.onreadystatechange = function() {
if (txtFile.readyState === 4) { // Makes sure the document is ready to parse.
if (txtFile.status === 200) { // Makes sure it's found the file.
allText = txtFile.responseText;
lines = txtFile.responseText.split("\r\n"); // Will separate each line into an array
} //"\r\n"
}
}
console.log($(txtFile).val());
var stringT = (new XMLSerializer()).serializeToString(txtFile);
but get the following error:
[11:22:43.970] NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMSerializer.serializeToString] @ http://127.0.0.1:8020/CharCount2/character_counter2.js:26\
any help would be very welcome. I'm thinking about re-writing my whole system in Python as i'm struggling with the limited I/O functionality of Javascript, and i have much more experience in Python
Upvotes: 0
Views: 1529
Reputation: 3568
Ajax does not work with the file:// protocol. You should use a simple webserver on your machine such as Apache or Nginx.
Upvotes: 3