AJAX 汽车详细信息练习

时间:2023-03-09 19:28:28
AJAX  汽车详细信息练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.11.2.min.js"></script>
<script src="tanchuang.js"></script>
<link href="tanchuang.css" rel="stylesheet" type="text/css" />
<?php
include("dbda.class.php");
$db=new dbda();
?>
</head> <body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>汽车名称</td>
<td>汽车系列</td>
<td>上市时间</td>
<td>信息</td>
</tr>
<?php
$sql="select * from car";
$attr=$db->Query($sql);
foreach($attr as $v)
{
echo "<tr>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td><input type='button' value='查看详情' class='aaa'
code='{$v[0]}' /></td>
</tr>";
} ?>
</table>
</body>
<script type="text/javascript">
$(document).ready(function(e) { $(".aaa").click(function(){ //找主键值
var code=$(this).attr("code"); //根据主键查询具体数据
$.ajax({ url:"AJAXlianxichuli.php",
data:{code:code},
type:"POST",
dataType:"TEXT",
success: function(data){ var lie=data.split("^"); var html = "<div class='qx'>代号:"+lie[0]
+"</div><div class='qx'>名称:"+lie[1]
+"</div><div class='qx'>系列:"+lie[2]
+"</div><div class='qx'>时间:"+lie[3]
+"</div><div class='qx'>油耗:"+lie[4]
+"</div><div class='qx'>功率:"+lie[5]
+"</div><div class='qx'>排量:"+lie[6]
+"</div><div class='qx'>价格:"+lie[7]+"</div>";
var win = new Window({ width : 300, //宽度
height : 400, //高度
title : '详细信息', //标题
content : html, //内容
isMask : true, //是否遮罩
isDrag:true, //是否移动 }); } }); }) });
</script>
</html>
<?php
$code=$_POST["code"]; include("dbda.class.php");
$db=new dbda(); $sql="select * from car where code='{$code}'"; $attr=$db->Query($sql); //$attr[0]代表一列,是一维数组 然后用implode分割变成字符串
echo implode("^",$attr[0]);