ThinkPHP实现删除的操作,现在是点击删除之后可以删除数据,但是返回的数据无法通过弹窗显示出来
前端代码:<td><spanclass="glyphiconglyphicon-edit"onclick="showManagerModify({$ml.id})"id=...
前端代码:
<td><span class="glyphicon glyphicon-edit" onclick="showManagerModify({$ml.id})" id="showManagerModify"></span> <a href="javascript:void(0)" onclick="deleteManager({$ml.id})"><span class="glyphicon glyphicon-trash"></span></a>
js代码:
function deleteManager($id){
layer.confirm('您确定要删除吗,删除之后不能恢复哦!',{
btn:['yes','no']
},function(){
todelete($id);
},function(){
layer.msg("取消成功",{icon:1});
});
}
function todelete($id) {
var url = '__URL__/deleteManager';
data = {};
data['id'] = $id;
$.post(
url,
data,
function(result){
if(result.status == 1) {
return dialog.success(result.message,'');
// 跳转到相关页面
}else {
return dialog.error(result.message);
}
}
,"JSON");
}
后端代码:
public function deleteManager(){
$id = I('id');
$res = D('Manager') -> deleteManagerById($id);
if(!$res){
return show(0,"删除失败");
}else{
return show(1,"删除成功");
}
}
show函数:
function show($status, $message,$data=array()) {
$reuslt = array(
'status' => $status,
'message' => $message,
'data' => $data,
);
exit(json_encode($reuslt));
} 展开
<td><span class="glyphicon glyphicon-edit" onclick="showManagerModify({$ml.id})" id="showManagerModify"></span> <a href="javascript:void(0)" onclick="deleteManager({$ml.id})"><span class="glyphicon glyphicon-trash"></span></a>
js代码:
function deleteManager($id){
layer.confirm('您确定要删除吗,删除之后不能恢复哦!',{
btn:['yes','no']
},function(){
todelete($id);
},function(){
layer.msg("取消成功",{icon:1});
});
}
function todelete($id) {
var url = '__URL__/deleteManager';
data = {};
data['id'] = $id;
$.post(
url,
data,
function(result){
if(result.status == 1) {
return dialog.success(result.message,'');
// 跳转到相关页面
}else {
return dialog.error(result.message);
}
}
,"JSON");
}
后端代码:
public function deleteManager(){
$id = I('id');
$res = D('Manager') -> deleteManagerById($id);
if(!$res){
return show(0,"删除失败");
}else{
return show(1,"删除成功");
}
}
show函数:
function show($status, $message,$data=array()) {
$reuslt = array(
'status' => $status,
'message' => $message,
'data' => $data,
);
exit(json_encode($reuslt));
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询