php第二十二节课
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>
<style type="text/css">
.sc
{
width:70px;
height:30px;
background-color:#66F;
color:white;
text-align:center;
line-height:30px;
vertical-align:middle;
font-size:20px;
}
.sc:hover
{
cursor:pointer;
background-color:#F60;
}
</style>
</head>
<body>
<input type="button" value="显示数据" id="btn" />
<table id="xianshi" width="100%" border="1" cellpadding="0" cellspacing="0">
</table>
</body>
<script type="text/javascript">
$("#btn").click(function(){
ShowAll();
BindCK();
})
function BindCK()
{
$(".sc").click(function(){
var code = $(this).attr("bs");
$.ajax({
url:"Delete.php",
data:{code:code},
type:"POST",
dataType:"TEXT",
success: function(data){
if(data.trim()=="OK")
{
ShowAll();
BindCK();
}
else
{
alert("删除失败!");
}
}
});
})
}
function ShowAll()
{
$.ajax({
async:false,
url:"ChuLi.php",
datatype:"TEXT",
success:function(data){
var str = "<tr><td>代号</td><td>姓名</td><td>操作</td></tr>";
var hang = data.split("|");
for(var i=0;i<hang.length;i++)
{
var lie = hang[i].split("^");
//str+="<tr><td>"+lie[0]+"</td><td>"+lie[1]+"</td><td>"+lie[2]+"</td><td>"+lie[3]+"</td><td>"+lie[4]+"</td><td></td></tr>";
str+="<tr>";
for(var j=0;j<lie.length;j++)
{
str+="<td>"+lie[j]+"</td>";
}
str+="<td><div class='sc' bs='"+lie[0]+"'>删除</div></td>";
str+="</tr>";
}
$("#xianshi").html(str);
}
});
}
</script>
</html>
<?php
include("../DBDA.php");
$db = new DBDA();
$sql = "select * from Nation";
//$attr = $db->Query($sql);
//echo "p001^张三|p002^李四|p003^王五";
/*$str = "";
foreach($attr as $v)
{
$str =$str. implode("^",$v);
$str = $str."|";
}
$str = substr($str,0,strlen($str)-1);
echo $str;*/
echo $db->StrQuery($sql);
<?php
$code = $_POST["code"];
include("../DBDA.php");
$db = new DBDA();
$sql = "delete from Nation where Code='{$code}'";
$r = $db->Query($sql,0);
if($r)
{
echo "OK";
}
else
{
echo "NO";
}
<!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>
</head>
<body>
<?php
include("../DBDA.php");
$db = new DBDA();
$sql = "select count(*) from Users where Uid = 'lisi'";
$attr = $db->StrQuery($sql);
echo $attr;
?>
</body>
</html>