Ajax无刷新技术:
1.Ajax请求
index.php
<?php
$servername = "localhost";
$username = "root";
$password = "133nubia022";
$dbname = "myweb";
// 创建连接
$conn = mysqli_connect($servername, $username, $password,$dbname);
$sql = "select * from user";
$rst = mysqli_query($conn,$sql);
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>
<style>
*{
font-family: 微软雅黑;
}
</style>
<link rel="stylesheet" href="bs/css/bootstrap.min.css">
<script src='bs/js/jquery.min.js'></script>
<script src='bs/js/bootstrap.min.js'></script>
</head>
<body>
<div class="container">
<h2 class='page-header'>查看用户:</h2>
<table class='table table-bordered table-hover'>
<tr>
<th>编号</th>
<th>用户名</th>
<th>密码</th>
<th>删除</th>
</tr>
<?php
while($row=mysqli_fetch_assoc($rst)){
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['usename']}</td>";
echo "<td>{$row['password']}</td>";
echo "<td><a href='javascript:' class='del' id='{$row['id']}'>删除</a></td>";
echo "</tr>";
}
?>
</table>
</div>
</body>
<script>
$('.del').click(function(){
id=this.id;
obj=$(this);
$.get('del.php',{id:id},function(r){
if(r=='1'){
obj.parent().parent().hide();
}
});
});
</script>
</html>
del.php
<?php
//ajax删除数据
$servername = "localhost";
$username = "root";
$password = "133nubia022";
$dbname = "myweb";
// 创建连接
$conn = mysqli_connect($servername, $username, $password,$dbname);
$id=$_GET['id'];
$sql="delete from user where id={$id}";
if(mysqli_query($conn,$sql)){
echo 1;
}