2

I am sending a key through DELETE method but the method seems inappropriate. Any clue what I am missing ? The function runs but the it does not work

$scope.delete = function(id) {
  if (confirm("Are you sure you want to delete the user") === true) {
    $http({
        method: 'DELETE',
        url: 'http://abc.dev/users/user/' + id,
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      })
      .success(function(data) {
        $scope.singleuser = data;
        console.log("function single user is processed");                   
      })
      .error(function(data) {
        console.log('error');
      });
  } else {
    console.log("no");
  }
};
10
  • Which Angular version are you using? Commented Sep 9, 2016 at 5:38
  • Is the server allowing delete methods? Do you get a 403 response? Commented Sep 9, 2016 at 5:39
  • 1
    What doesn't work? Is neither of success of error callbacks getting called? Are you getting any errors in the JS console? Commented Sep 9, 2016 at 5:40
  • @thepio I am using angular1 Commented Sep 9, 2016 at 5:40
  • 1
    Look At This Link. stackoverflow.com/questions/22055251/… Commented Sep 9, 2016 at 5:40

2 Answers 2

0

The issue was in the API, as the API is written in Yii framework and in the main.config file where we define the rules there were spaces array('users / delete', 'pattern' => 'users / <model:\w+>/<id:\d+>', 'verb' => 'DELETE'), like this I removed the spaces and it worked.

Final rule

array('users/delete', 'pattern' => 'users/<model:\w+>/<id:\d+>', 'verb' => 'DELETE'),
Sign up to request clarification or add additional context in comments.

Comments

0

You are getting 404 means you have not defined the DELETE method API at the back-end.

First of all defined it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.