[英]reading a text file line by line using javascript
我正在嘗試從這種格式的文本文件中讀取行; 34.925,150.977 35.012,151.034 34.887,150.905
我目前正在嘗試使用這種方法,但顯然不起作用。 任何幫助,將不勝感激。
var ltlng = [];
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "C:\Gmap\LatLong\Coordinates.txt", true);
txtFile.onreadystatechange = function() {
if (txtFile.readyState === 4) {
if (txtFile.status === 200) { // Makes sure it's found the file.
lines = txtFile.responseText.split("\n"); // separate each line into an array
ltlng.push(new google.maps.LatLng(lines.split(",")[0],lines.split(",")[1]); //create the marker icons latlong array
}
}
}
當通過HTTP/S
協議(而不是file
協議)調用資源時, XMLHttpRequest
起作用
因此,要使代碼正常工作,您應該將此代碼與網絡服務器一起嘗試
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.