ajax循环数据
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <input type="button" value="按钮" /> 10 <ul class="txtBox"> 11 12 </ul> 13 <script src="http://vscss.com/dm/jquery.js"></script> 14 <script src="ajax.js"></script> 15 <script> 16 $(function(){ 17 $('input').click(function(){ 18 ajax('duanmu.txt?dm='+new Date().getTime(),function(str){ 19 var arr = eval(str); 20 var $html = ""; 21 for(var i=0;i<arr.length;i++) { 22 $html += '<li>用户名:<span class="userTxt">'+arr[i].user+'</span>,密码:<span class="passTxt">'+arr[i].pass+'</span></li>'; 23 }; 24 $($html).appendTo('.txtBox'); 25 },function(){ 26 alert('失败'); 27 }) 28 }); 29 }); 30 </script> 31 </body> 32 </html>
[{user: 'blue', pass: '123456'},{user: '张三', pass: '654321'},{user: '李四', pass: '789456'},{user: '王五', pass: '7777'}]
posted on 2016-06-18 02:19 jasonduanmu 阅读(400) 评论(0) 编辑 收藏 举报