I am trying to read a text file using jquery, like this:
// LOAD file and split line by line and append divs
$.get('myFile.txt', function(data) {
var lines = data.split("
");
$.each(lines, function(n, elem) {
$('#myContainer').append('<div>' + elem + '</div>');
});
});
In chrome, I am getting:
XMLHttpRequest cannot load file:///C:/myPath/myFile.txt. Origin null is not allowed by Access-Control-Allow-Origin.
Firefox shows no error but the code is not executed (I have breakpoints in firebug and the anonymous function never runs).
Any help appreciated!
EDIT:
had to:
- use the file full path
- launch
chrome with
"--allow-file-access-from-files"
now it's working OK!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…