$.get发送GET请求,并接收返回结果集,主页面INDEX.PHP
<script>
$(function(){
//function ajax(){
$.get("comment.php?id=1",function(data){
$("div").html(data);
})
//};
})
</script>
<DIV></DIV>
comment.php页
<?php header("Content-type: text/html; charset=gb2312");
//$mypdo=new pdo("mysql:host=localhost;dbname=news","root","");
$mypdo=new pdo("mysql:host=localhost;dbname=news;","root","");
$mypdo->query("set names gb2312");
$id=$_GET['id'];
$sql="selects id,title from news where id=$id limit 0,20";
$stmt=$mypdo->query($sql);
$rows=$stmt->fetchAll();
foreach($rows as $rs){
echo $rs['title']."<br>";
}
?>