怎么通过json向ajax发送数据以table的形式输出
1个回答
展开全部
<div id='a'></div>
<script>
$(function(){
$.ajax({
type:"POST",
url:"2.php",
success:function(msg){
var arr = eval('('+msg+')');
for(var item in arr){
//console.log('<table><tr><td>'+arr[item][0]+'</td><td>'+arr[item][1]+'</td><tr></table>');
var html = '<table border="1px"><tr><td>'+arr[item][0]+'</td><td>'+arr[item][1]+'</td><tr></table>';
$('#a').append(html);
}
}
});
});
</script>
$arr = array('0'=>array('0'=>'1sac','1'=>'1vffff'),'1'=>array('0'=>'2sac','1'=>'2vffff'),'2'=>array('0'=>'3sac','1'=>'3vffff'));
echo json_encode($arr);
<script>
$(function(){
$.ajax({
type:"POST",
url:"2.php",
success:function(msg){
var arr = eval('('+msg+')');
for(var item in arr){
//console.log('<table><tr><td>'+arr[item][0]+'</td><td>'+arr[item][1]+'</td><tr></table>');
var html = '<table border="1px"><tr><td>'+arr[item][0]+'</td><td>'+arr[item][1]+'</td><tr></table>';
$('#a').append(html);
}
}
});
});
</script>
$arr = array('0'=>array('0'=>'1sac','1'=>'1vffff'),'1'=>array('0'=>'2sac','1'=>'2vffff'),'2'=>array('0'=>'3sac','1'=>'3vffff'));
echo json_encode($arr);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询