我正在尝试使用$ 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;
});
我在这里缺少什么?
答案 0 :(得分:3)
第二个参数delete()
期望是具有http请求配置的对象。传递data
时不是一些字符串:
$http.delete('http://example.com/myapp.php?',
data, {
[...]