在 Angular js 中通过 DELETE 方法发送数据
Sending data through DELETE method in Angular js
我正在通过 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");
}
};
问题出在 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'),
你得到 404
意味着你有 not defined the DELETE method API
在后端。
首先定义一下。
我正在通过 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");
}
};
问题出在 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'),
你得到 404
意味着你有 not defined the DELETE method API
在后端。
首先定义一下。