I want to read text file's comma separated variables in a java script array right now i have hard coded values like this
var arrUserTags = new Array('{{Name}}','{{Address}}','{{Company}}');
but i want to read it from a text file dynamically on page load how can i read it?
I am done with below solution but now i am facing 1 more problem. When i do changes to text file that don't become effective, while the browser takes the old values only? How to sort it out?
You need AJAX to load the file:
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", path, true);
xmlhttp.send();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
parse(xmlhttp.responseText);
}
}
And then Split the text:
function parse (text) {
var array = text.split(",");
//Do something
}
出于安全原因 ,您不能使用Javascript(不是在谈论服务器端js,例如node.js)来读取本地文件系统文件,而是可以使用某些服务器端语言(例如PHP,JSP等)来读取本地文件系统文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.