index.php页面:
<script src="jquery-1.7.1.min.js"></script>
<script>
$(function(){
$('#btn').click(function(){
$.get('show.php',{'id':2},function(data){
var json = JSON.parse(data);
for(i in json){
document.write(json[i]['name']);
}
//console.log(json[0]['name'])
//document.write(data);
})
})
})
</script>
show.php页面:
<?php
$pdo=new pdo('mysql:host=localhost;dbname=stu','root','');
$pdo->query('set names utf8');
$sql="selectxxx * from xs";
$stmt=$pdo->query($sql);
$rs=$stmt->fetchAll();
$json = json_encode($rs);
echo ($json);
?>