使用Angular $ http.delete导致TypeError

时间:2016-02-04 17:29:25

标签: angularjs

我正在尝试使用$ http.delete发送DELETE命令,但收到错误:

TypeError --> Cannot create property 'method' on string 'user_id=5&response=This+is+a+test.'

当我在控制器中执行命令时如下:

在控制器中:

.controller(myController', function($scope) {

    var something = {
      user_id: 1,
      text: 'This is a test.'
    }

     MyFactory.deleteSomething(something);
});

在服务中:

.factory('MyFactory', function($http) {

var service = {};

service.deleteSomething = function(something) {

var data = $.param(something);
var promise =  $http.delete('http://example.com/myapp.php?',
data, {
  headers: {
    'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
  }
})
  .success(function(data,status) {
    console.log("Delete success!");
    return data;
  })
  .error(function(data, status, header, config) {
    console.log("Delete FAILED!");
  });
return promise;
   }
return service;
});

我在这里缺少什么?

1 个答案:

答案 0 :(得分:3)

第二个参数delete()期望是具有http请求配置的对象。传递data时不是一些字符串:

$http.delete('http://example.com/myapp.php?', data, { [...]