【问题标题】:Sending data through DELETE method in Angular js在Angular js中通过DELETE方法发送数据
【发布时间】:2017-01-17 04:24:42
【问题描述】:

我正在通过 DELETE 方法发送密钥,但该方法似乎不合适。任何线索我错过了什么?该函数运行但它不起作用

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

【问题讨论】:

  • 您使用的是哪个 Angular 版本?
  • 服务器是否允许delete 方法?收到 403 响应了吗?
  • 什么不起作用?错误回调的成功都没有被调用吗?您是否在 JS 控制台中遇到任何错误?
  • @thepio 我正在使用 angular1

标签: javascript angularjs sql-delete


【解决方案1】:

问题出在 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'),

【讨论】:

    【解决方案2】:

    你得到404意味着你有not defined the DELETE method API 在后端。

    首先定义它。

    【讨论】:

      猜你喜欢
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      相关资源
      最近更新 更多