js读取服务器端的txt文件有两种方式:
1、ajax方式读取文件
var url = "http://10.22.19.150:8080/timer/resources/";
var htmlobj= $.ajax({url:url,async:false});
var dataString = ;
// var data =(dataString);
var data = eval("("+ dataString +")");//转换为json对象();
var status = data["status"];
var personScoreList = data["list"];
2、使用XMLHttpRequest读取文件
var url = "http://10.22.19.150:8080/timer/resources/";
var xmlhttp = null;
try {
xmlhttp = new ActiveXObject("");
} catch(e) {
try {
xmlhttp = new ActiveXObject("");
} catch(e) {}
}
if (!xmlhttp) xmlhttp = new XMLHttpRequest();
= function() {
if ( == 4) {
if( == 200){
var s = ;
alert("XMLHttpRequest = " + s);
s = (//g, ">");
xmlhttp = null;
}
}
};