在我的网站上,我有这样的内容:
<div class="mdl-cell--4-col mdl-grid">
<label class="mdl-cell--6-col">Liste administrateurs</label>
<select class="mdl-cell--6-col" ng-model="adminselected" ng-options="admin for admin in listAdmins">
</select>
</div>
<div class="mdl-cell--2-col mdl-grid">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="float: right" layout-align="end center" ng-click="deleteAdmin()">Supprimer</button>
</div>
listAdmins 在 Controller 中通过以下方式进行管理:
-带有身份验证的初始化:
forecastValue.authentification()
.then(function(report) {
$scope.currentName = report[0].informationUser.id_name;
forecastValue.getAdmins($scope.currentName)
.then(function(reports) {
$scope.listAdmins = reports[0].listAdmins;
console.log(reports[0].listAdmins);
}).catch(function(err) {
$scope.listAdmins= [];
console.error('Unable to fetch forecast report: ' + err);
});
}).catch(function(err) {
$scope.currentName= '';
console.error('Unable to fetch forecast report: ' + err);
});
-删除管理员的功能,它是在post请求中的工厂部分中传输后的。
$scope.deleteAdmin = function() {
forecastValue.deleteAdmin($scope.adminselected)
.then(function(report){
console.log("Changes saved");
$scope.adminmessage = "L'utilisateur "+ $scope.adminselected+" n'est plus administrateur";
}).catch(function(err){
console.error("Changes not saved");
});
forecastValue.getAdmins($scope.currentName)
.then(function(reports) {
$scope.listAdmins = reports[0].listAdmins;
}).catch(function(err) {
$scope.listAdmins= [];
console.error('Unable to fetch forecast report: ' + err);
});
};
下一个是在 Node.js 代码中执行的 MySQL 请求:
function deleteAdmin(res, queryParams)
{
connection.query("DELETE FROM safeplusdb.admin WHERE name=\""+(decodeURIComponent(queryParams.admindeleted))+"\";");
res.send({
state: "OK"
});
}
所以,结果如下:
-我查看数据库,用Workbench软件,数据被删除了。
-在网站中,没有任何内容注册,即使我按 F5 或 CTRL+F5,数据仍然在这里。 进行更改的唯一方法是停止应用程序并使用命令“node server.js”重新启动它。
当我使用更新SQL方法时,我没有遇到这样的问题。
怎么解释?
最佳答案
解决方案:
function deleteAdmin(res, queryParams)
{
connection.query("DELETE FROM safeplusdb.admin WHERE name=\""+(decodeURIComponent(queryParams.admindeleted))+"\";", function(err, records){
if(err) throw err;
connection.query("SELECT * FROM safeplusdb.admin;", function (err, records){
if(err) throw err;
adminlist=[];
for(i=0; i<records.length; i++)
{
adminlist[i]=records[i].name;
}
res.send({
state: "OK"
});
});
});
}
这个想法是在基础上发出 SELECT 请求,插入 DELETE 请求,以便立即刷新 Web 浏览器的所有数据。它有效!
关于mysql - 请求 "DELETE"未由应用程序注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43898198/