您的位置:首页 > 编程语言 > PHP开发

php原始代码实现无刷新删除

2016-10-31 09:21 543 查看
stu.php

<?php

header("content-type:text/html;charset=utf8");

//连接数据库

$link = mysql_connect("127.0.0.1","root","") or die("连接失败");

//选择数据库

$re = mysql_select_db("practice",$link) or die("选择失败");

//写SQL语句

$arr = "select * from user join zu on user.z_id = zu.z_id";

//执行

$moov=mysql_query($arr);

//echo $moov;

?>

<div id="list">

<table border=1>

  <tr>

    <th>编号</th>

    <th>用户名</th>

    <th>组名</th>

    <th>操作</th>

  </tr>

  <?php 

   while($arr=mysql_fetch_assoc($moov)){
  ?>

    <tr>
<td><?php echo $arr['u_id']?></td>
<td><?php echo $arr['u_name']?></td>
<td><?php echo $arr['z_name']?></td>
<td>
<a href="javascript:delItem('<?php echo $arr['u_id']?>')">移除</a>
</td>
</tr>
<?php

   }  

  ?>

</table>

</div>

<script type="text/javascript" src="jquery.js"></script> 

<script>

function delItem (u_id) {

$.get('delete.php?u_id='+u_id,null,function (msg) {//ajax请求,请求后执行下面代码

if ('1'==msg) {//返回1表示成功

$('#t'+u_id).remove();//把id为txx 的表格删除

} else {//否则弹出错误信息

$('#list').html(msg);

}

});

}

</script>

delete.php

<?php

header("content-type:text/html;charset=utf8");

require('stu.php'); 

//接受数据

$u_id=$_GET['u_id'];

//连接数据库

$link = mysql_connect("127.0.0.1","root","") or die("连接失败");

//选择数据库

$re = mysql_select_db("practice",$link) or die("选择失败");

//写SQL语句

$arr = "delete from user where u_id = $u_id";

//执行

$moov=mysql_query($arr);

if($moov){
//echo "<script>alert('成功');locahref='stu';</script>";
echo header("location:stu.php");

}else{
echo "<script>alert('失败');locahref='stu';</script>";

}

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: