<a onclick="ajax();">...</a></li>
<table class="table tile" id="123">
<thead>
<tr>
<th>Number</th>
<th>Title</th>
<th>Url</th>
<th>Describe</th>
</tr>
</thead>
<tbody>
<tr>
<td id="resText_1">Number</td>
<td id="resText_2">Title</td>
<td id="resText_3">Url</td>
<td id="resText_4">Describe</td>
</tr>
</tbody>
</table>
function ajax() {
//声明异步请求对象:
var xmlHttp = null;
if (window.ActiveXObject) {
// IE6, IE5 浏览器
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari 浏览器
xmlHttp = new XMLHttpRequest();
}
//如果实例化成功,调用open()
if (xmlHttp != null) {
xmlHttp.open("get", "links.txt", true);
xmlHttp.send();
xmlHttp.onreadystatechange = doResult; //设置回调函数
}
function doResult() {
if (xmlHttp.readyState == 4) { //4表示执行完成
if (xmlHttp.status == 200) { //200表示执行成功
//获取txt行数
var lineArray = xmlHttp.responseText.split(‘\n‘);
for(var i = 0; i<lineArray.length;i++){
var line = lineArray[i];
}
//分别输出第1,2,3,4行
$("#resText_1").html(lineArray[0]);
$("#resText_2").html(lineArray[1]);
$("#resText_3").html(lineArray[2]);
$("#resText_4").html(lineArray[3]);
}
}else{
alert("error");
}
}
}
1
2
3
4
https://blog.csdn.net/luyanc/article/details/79470900
原文:https://www.cnblogs.com/nephkis/p/12849407.html