0

Please help me through this m trying from many days to learn basic crud operations in angularjs I just got output for display table data(using $http.get) next am trying to perform delete but m getting CORS error. yes, but the record gets deleted successfully.

my code igniter function is like this:

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');
}

controller function in angularjs:

$scope.delete = function(id)
{         
$http.delete('http://localhost/**/****/*****/users/delete_user/'+ id)
.then(function(response){
$scope.userList= response.data; 
});
}
sonuD
  • 47
  • 9

2 Answers2

0

As you've already added OPTIONS

just add

if ( "OPTIONS" === $_SERVER['REQUEST_METHOD'] ) {
    die();
}

See also this answer

Shubham Sharma
  • 315
  • 2
  • 18
0

Got the o/p, i would like to post the answer just to help newbies. my new code is:

$scope.delete = function(id)
{     
confirm("Are you sure?"); 
$http.post('http://localhost/******/users/delete_user/'+ id)
.then(function(response){
$state.transitionTo('dashboard.users');

});
}
sonuD
  • 47
  • 9