我有兩個.txt文件,我試圖從中創建組合。我試圖把每個文件都放到一個數組中,因爲每個單詞都被換行符隔開。問題是,當我運行$.get
時,它不會將任何信息保存到陣列。這裏是我的代碼:jQuery將文件行存儲到數組
<html>
<head>
<title>Email Validator</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<span id="runtime"></span>
<table class="results">
<tr>
<td>First Name</td>
<td>Last Name</td>
</tr>
</table>
<script>
//pull firstnames and store to array
var firstnames = new Array();
$.get('first.txt', function(data){
firstnames = data.split("\n");
});
//pull lastnames and store to array
var lastnames = new Array();
$.get('last.txt', function(data){
lastnames = data.split("\n");
});
var fn, ln;
//firstnames
$.each(firstnames , function(findex, fvalue) {
fn = fvalue;
//lastnames
$.each(lastnames , function(lindex, lvalue) {
ln = lvalue;
$("table.results").appendTo("<tr><td>" + fn + "</td><td>" + ln + "</td></tr>");
});
});
</script>
</body>
</html>