php ajax 删除模块代码
php ajax 删除模块代码
js部分:
<a href="javascript:void(0)" onclick="javascript:return del(<?php echo $t['id'];?>);" id="btndel" >删除 </a> function del(id) { var id =id; var url = "/admin/cate_del.php"; var data = {'id':id}; layer.open({ type : 0, title : '是否提交?', btn: ['yes', 'no'], icon : 3, closeBtn : 2, content: "是否确定删除", scrollbar: true, yes: function(){ // 执行相关跳转 $.post( url, data, function(s){ if(s.status == 1) { return dialog.success(s.message,''); // 跳转到相关页面 }else { return dialog.error(s.message); } } ,"JSON"); }, }); }
php部分:
//引入配置文件 require_once('../public/common/config.php'); require_once('../public/common/functions.php'); check_login(); if(empty($_POST['id'])){ exit('缺少必要的参数'); } $id = $_POST['id']; $sql ="delete from kc_cate where id=({$id})"; try { $row =sql_excute($sql); if($row=1) { return show(1,'分类名称删除成功'); }else { return show(0,'分类名称删除失败!'); } }catch(Exception $e) { return show(0,$e->getMessage()); } function show($status,$message,$data=array()){ $result = array( 'status' => $status, 'message'=>$message, 'data'=>$data, ); exit(json_encode($result)); }
上一篇:php异常处理 异常捕获示例代码
下一篇:PHP循环结构 for循环