ajax实现改变状态和删除无刷新的实例
来源:
中文源码网 浏览:165 次 日期:2024-05-02 16:12:53
【下载文档: ajax实现改变状态和删除无刷新的实例.txt 】
ajax实现改变状态和删除无刷新的实例
1. 01.php为主程序,调用smarty模板遍历输出:
include './include/Mysql.class.php';
include './libs/Smarty.class.php';
$db=new Mysql;
$smarty=new Smarty;
$lists=$db->getALL('users');
$smarty->assign('lists',$lists);
$smarty->display('list.html');
?>
2. list.html模板:内容结合JS ajax使用:
用户权限展示表//给table体设置一个div,方便js调用
用户权限表
uid | 用户名 | 密码 | 锁定状态 | 角色 | 操作 |
---|
{foreach $lists as $list}
{$list.uid} |
{$list.username} |
{$list.password} |
{if $list.is_lock==1}
锁定 |
{else}
取消锁定 |
{/if}
{if $list.role==1}
管理员 |
{else}
编辑者 |
{/if}
删除 |
{/foreach}
3. 02.php改变状态无刷新:
include './include/Mysql.class.php';
include './libs/Smarty.class.php';
$lock=$_POST['is_lock'];
$uid=$_POST['uid'];
$smarty=new Smarty;
$db=new Mysql;
$result=$db->update('users',"is_lock=$lock","uid=$uid");
if($result){
//修改成功重新遍历数据库并输出smarty模板
$lists=$db->getALL('users');
$smarty->assign('lists',$lists);
$smarty->display('list.html');
}else{
echo false;
}
?>
4.del.php实现删除无刷新
include './include/Mysql.class.php';
include './libs/Smarty.class.php';
$db=new Mysql;
$smarty=new Smarty;
$uid=$_POST['uid'];
$res=$db->delete('users',$uid);
if($res>0){
$lists=$db->getALL('users');
$smarty->assign('lists',$lists);
$smarty->display('list.html');
}else{
echo false;
}
?>
以上这篇ajax实现改变状态和删除无刷新的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持中文源码网。