
下面小编就为大家分享一篇ajax实现改变状态和删除无刷新的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
1. 01.php为主程序,调用smarty模板遍历输出:
<?php 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调用
3. 02.php改变状态无刷新:
<?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实现删除无刷新
<?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实现改变状态和删除无刷新的实例的详细内容,更多请关注易知道|edz.cc其它相关文章!