2016-09-09 34 views
2

我通過DELETE方法發送密鑰,但該方法似乎不合適。任何線索我失蹤了?該函數運行,但它不工作通過DELETE方法在Angular js中發送數據

$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"); 
    } 
}; 
+0

您使用的是哪個角度版本? – thepio

+0

服務器是否允許「刪除」方法?你有403迴應嗎? – mkaran

+1

什麼不行?錯誤回調的成功是否被調用?你在JS控制檯中遇到任何錯誤? – iamgame

回答

0

的問題是在API中,由於API是寫在Yii框架,並在main.config文件,其中我們定義的規則有空間array('users/delete', 'pattern' => 'users/<model:\w+>/<id:\d+>', 'verb' => 'DELETE'),這樣我刪除了空間,它的工作。

最終規則

array('users/delete', 'pattern' => 'users/<model:\w+>/<id:\d+>', 'verb' => 'DELETE'), 
0

你得到404意味着你必須not defined the DELETE method API 在後端。

首先定義它。