<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="button" name="#" id="btn" value="请求">
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
// var oBtn=document.getElementById('btn');
// oBtn.onclick=function(){
// ajax('a.txt',function(s){
// console.log(s);
// },function(){
// alert("请求发生错误");
// })
// }
//以上代码 console.log 出来的内容是 aa.txt里的内容 这是ajax请求得到的东西1
var oBtn=document.getElementById('btn');
oBtn.onclick=function(){
ajax('arr.txt',function(s){
console.log(s);
var arr=eval(s)//把扔回来的东西,变成数组
var newStr='';
for(var i=0;i<arr.length;i++){
newStr+=arr[i];
}
console.log(newStr);
},function(){
alert('请求发生了错误');
})
}
</script>
</body>
</html>