【发布时间】:2014-10-07 04:25:19
【问题描述】:
我需要一些帮助来解决我的问题。 我有一个用户列表,我想在 CI HMVC 中使用 ajax 删除用户 onclick 删除按钮。这是我的列表视图的代码
$(function() {
$(".tip-del").click(function() {
var recId = $(this).data("id");
var parent = $(this).parent();
var BASE_URL = "<?php echo base_url()?>";
var r = confirm("Are you sure you want to delete this user?");
if(r == true){
$.ajax({
url : BASE_URL + 'auth/delete_user',
type: 'post',
data: {'rec_id' : recId },
success: function (response){
try{
if(response == 'true'){
parent.slideUp('slow',function(){$(this).remove();});
}
}catch(e) {
alert('Exception while request..');
}
},
error: function (xhr, text, message) {
console.log(message);
}
});
return false;
}
});
});
这是我的控制器(视图所在的同一模块)代码
function delete_user() {
if ($this->input->post('rec_id')) {
$id = $this->input->post('id');
}
if (!$this->ion_auth->in_group('admin')) {
$this->session->set_flashdata('message', $this->lang->line("access_denied"));
$data['message'] = (validation_errors() ? validation_errors() : $this->session->flashdata('message'));
redirect('module=auth&view=users', 'refresh');
}
$this->ion_auth_model->deleteUser($id);
}
这是我的模型代码
public function deleteUser($id) {
if ($this->db->delete('users', array('id' => $id)) && $this->db->delete('users_groups', array('user_id' => $id))) {
return true;
}
return FALSE;
}
任何人都可以帮我解决这个问题。我不明白我出了什么问题。在 ajax 响应的预览中,我得到了错误
An Error Was Encountered. The action you have requested is not allowed.
提前致谢。
【问题讨论】:
-
是否存在与错误相关的行号和文件,或者是从 codeigniter 返回的 Web 视图?
-
您检查以确保您的 db 用户具有执行 delete() 的适当权限,这可能是问题所在。
标签: php jquery ajax codeigniter hmvc