例子:将data读到的数据读取到页面中并加入到ul中 data.txt
[{user: 'blue', pass: '123456'},{user: '张三', pass: '654321'},{user: '李四', pass: '789456'},{user: '王五', pass: '7777'}] <script src="ajax.js"></script> <script> window.onload=function () { var oBtn=document.getElementById('btn1'); var oUl=document.getElementById('ul1'); oBtn.onclick=function () { ajax('data.txt?t='+new Date().getTime(), function (str){ var arr=eval(str); for(var i=0;i<arr.length;i++) { var oLi=document.createElement('li'); oLi.innerHTML='用户名:<strong>'+arr[i].user+'</strong>密码:<span>'+arr[i].pass+'</span>'; oUl.appendChild(oLi); } }, function (){ alert('失败'); }); }; }; </script> </head> <body> <input id="btn1" type="button" value="读取" /> <ul id="ul1"> </ul> </body>