簡體   English   中英

使用javascript逐行讀取文本文件

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM