ajax 新闻实例和数组
<html>
<head>
<title>demo.html</title>
<script src="jquery.js"></script>
</head>
<body>
<input type="button" value="获取新闻列表">
<div id="info">
<!-- 图片可在www.ajaxload.info 中挑选下载 -->
<img src="ajax-loader.gif" id="loading" style="display:none;">
<ul></ul>
</div>
<script>
$('input').click(function(){
$.ajax({
url:'demo.php?'+Math.random(),
type:'get',
success:function(data){
var result = eval(data);
for(var i = 0; i<result.length; i++){
$('ul').append('<li>'+result[i].title+'<em>'+result[i].publicTime+'</em></li>');
}
}
});
});
$(document).ajaxStart(function(){
$('#loading').show();
}).ajaxStop(function(){
$('#loading').hide();
});
</script>
</body>
</html>
demo.php
<?php
header('Content-type:text/html;charset:utf-8');
sleep(3);
echo '[
{
"title":"否认放松计划生育政策",
"publicTime":"2011-11-16";
},{
"title":"劳教制度建设",
"publicTime":"2011-11-15";
},{
"title":"中共中央决定废止劳教制度",
"publicTime":"2011-11-14";
}
]';
?>