php代码<?php$arr=array(array('id'=>'5','title'=>'akhkah','mesage'=>'ajax数组'),array('id'=>'6','title'=>
php代码<?php$arr=array( array('id'=>'5','title'=>'akhkah','mesage'=>'ajax数组'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组ggggggggggggg'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组ggggggggggggg'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组ggggggggggggggg'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组hhhhhhhhhhhhhh'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组sssssssssssss'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组aaaaaaaaaaaaaaa'), array('id'=>'6','title'=>'akhka666h','mesage'=>'ajax66数组aaaaaaaaaaaa'));$json=json_encode($arr);echo $json;//echo '[{"title":"ajax返回json与数组的组合格式"}]';?>html 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>json与数组的组合</title><script type="text/javascript" src="../../jquery-1.3.1.js"></script><script> $(function(){ $('#button').click(function(){ $.ajax({ url:'server.php?'+Math.random(), type:'get', success:function(data){ res=eval(data); for(var i=0;i<res.length;i++){ $('#content').append('<li><span>'+res[i].title+'</span><span>'+res[i].mesage+'</span></li>'); } } }); $(document).ajaxStart(function(){ $('#msg').show(); }); $(document).ajaxStop(function(){ $('#msg').hide(); }); });}); </script></head><body><button id="button">json与数组的组合</button><div id='msg'style="display:none;height:50px;background-color:red">数据加载中</div> <div id="content"> </div></body></html>