//index.php
<table width="100%" border="1pt solid black" cellspacing="0" cellpadding="5">
<?php
include("conn.php");
$resultx = mysql_query("SELECT * FROM news ORDER BY id DESC");
while ($rowx=mysql_fetch_array($resultx)) {
?>
<tr>
<td><?php echo $rowx[0];?></td>
<td><?php echo $rowx[1];?></td>
<td><input type='button' id='btn<?php echo $rowx["id"];?>' value="详情" onclick="key(<?php echo $rowx["id"];?>)">
<div id="text<?php echo $rowx[0];?>"></div>
</td>
</tr>
<?php } ?>
</table>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script>
function key(v){
$.ajax({
type:"get",
url:'server.php',
data:{ "id":v,},
dataType:"json",
success:function(data){
for (var a in data){
$('#text'+v).append(data[a]['id']+":"+data[a]['xm2']+"<br>");
}
$('#btn'+v).hide();
},
});
};
</script>
//server.php
<?php
include("conn.php");
$id=$_GET["id"];
$result=mysql_query("SELECT * FROM news2 where xm1='$id' ORDER BY id DESC");
$results=array();
while ($row=mysql_fetch_assoc($result)) {
$results[]=$row;
}
echo json_encode($results);
?>
ajax点击显示更多实例(静态更新)
最新推荐文章于 2024-10-01 19:27:44 发布