我正在尝试删除http请求。我在前端使用AngularJS,后面使用Node.js和PostgreSQL。
我想要的是能够根据其ID删除会话,但是由于某种原因,它只会删除id而不是其他ID。
所以,如果我有
id 1 身份2 id 3
我的删除请求将删除ID 1,但不会为其他人工作。
这是我的代码
HTML
ng-click="cancelUserSession()"
控制器
$scope.cancelUserSession = (userId) => {
const subtracting = currentIndex - 1;
if (subtracting <= 0) {
swal({
title: "Cancel Session",
type: "warning",
showCancelButton: true,
confirmButtonText: "Cancel",
cancelButtonText: "Keep",
animation: "slide-from-top"
},
() => {
loginService.cancelUserSession(userId).then((response) => {
console.log(response);
console.log("session canceled")
getSessions();
})
})
}
};
服务
this.cancelUserSession = (userId) => {
return $http({
method: "DELETE",
url: '/remove-session/' + userId
}).then((response) => {
return response;
})
};
index.js
app.delete('/remove-session/:userId', userCtrl.userCancelSession);
userCtrl
userCancelSession: (req, res) => {
app.get('db').delete_client_session([req.params.userId]).then(response => {
res.status(200).send(response + "item removed succesfully")
}).catch(err => console.log(err))
},
SQL
delete from client_sessions
where client_sessions.id = $1;