HTML源代码
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" xml:lang="en"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 5 <title>demo3</title> 6 <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> 7 <script> 8 $(function(){ 9 $(‘input‘).click(function(){ 10 var ul = $(‘#info>ul‘); 11 $.ajax({ 12 url:‘demo3.php?‘+Math.random(), 13 type:‘get‘, 14 success:function(data){ 15 var result = eval(data); 16 for(var i = 0;i<result.length;i++){ 17 // result[i].title; 18 ul.append(‘<li>‘+result[i].title+‘<em>‘+result[i].publicTime+‘</em></li>‘); 19 } 20 } 21 }); 22 }); 23 }); 24 </script> 25 </head> 26 <body> 30 <input type="button" value="获取新闻列表" /> 31 32 <div id="info"> 33 <ul></ul> 34 </div> 35 37 </body> 38 </html>
PHP源代码
1 <?php 2 echo ‘[ 3 { 4 "title":"否认放松计划生育政策", 5 "publicTime":"2011-11-11", 6 "content":"xiaofei" 7 8 }, 9 { 10 "title":"劳教制度简史", 11 "publicTime":"2013-2-4" 12 }, 13 { 14 "title":"**决定废止劳教制度", 15 "publicTime":"2014-1-20" 16 } 17 ]‘; 18 ?>