Javascript Can';无法让删除http请求正常工作
我正在尝试让删除http请求正常工作。我在前端使用AngularJS,在后端使用Node.js和PostgreSQL 我希望能够根据会话id删除会话,但由于某些原因,它只删除1的id,而不删除其他id 所以如果我有 id 1 id 2 id 3 我的删除请求将删除id 1,但对其他id无效 这是我的密码 HTML 控制器Javascript Can';无法让删除http请求正常工作,javascript,angularjs,node.js,postgresql,Javascript,Angularjs,Node.js,Postgresql,我正在尝试让删除http请求正常工作。我在前端使用AngularJS,在后端使用Node.js和PostgreSQL 我希望能够根据会话id删除会话,但由于某些原因,它只删除1的id,而不删除其他id 所以如果我有 id 1 id 2 id 3 我的删除请求将删除id 1,但对其他id无效 这是我的密码 HTML 控制器 $scope.cancelUserSession = (userId) => { const subtracting = currentIndex - 1;
$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();
})
})
}
};
index.js
app.delete('/remove-session/:userId', userCtrl.userCancelSession);
用户控制
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
您可以记录userCtrl中的req.params.userId吗?是的,每次控制台都会记录1。
app.delete('/remove-session/:userId', userCtrl.userCancelSession);
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))
},
delete from client_sessions
where client_sessions.id = $1;