请通过许多天来帮助我学习angularjs中的基本操作,我刚刚获得了用于显示表数据的输出(使用$ http.get),接下来我尝试执行删除但遇到了CORS错误。是的,但是记录已成功删除。
我的代码点火器功能如下:
public function delete_user($user_id){
header('Content-Type: application/json;charset=UTF-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: DELETE, HEAD, GET, OPTIONS, POST,
PUT');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-
Disposition, Content-Description');
$this->users_model->delete_user($user_id);
redirect('Users/index');
}
angularjs中的控制器功能:
$scope.delete = function(id)
{
$http.delete('http://localhost/**/****/*****/users/delete_user/'+ id)
.then(function(response){
$scope.userList= response.data;
});
}
答案 0 :(得分:0)
答案 1 :(得分:0)
知道了,我想发布答案只是为了帮助新手。我的新代码是:
$scope.delete = function(id)
{
confirm("Are you sure?");
$http.post('http://localhost/******/users/delete_user/'+ id)
.then(function(response){
$state.transitionTo('dashboard.users');
});
}