我正在使用express来构建一个非常基本的应用程序,我在这个应用程序中使用angular 1.2.16,angular-resource 1.2.16我从数据库查询名称并尝试删除名称req转到服务器但是服务器它说未定义和浏览器显示错误的空响应我试图找出我使用req.body.id
和req.query.id
的问题,但这些也无法正常工作
//controller
app.controller('NameController',['$scope','$resource',function($scope,$resource)
{ var nameResource=$resource('/api/Names');
nameResource.query(function(results)
{
$scope.Names=results;
});
$scope.Names=[];
$scope.remove=function(id,index)
{
nameResource.$delete(id);
console.log(id);
$scope.Names.splice(index, 1);
}
}]);
//route
app.delete('/api/Names',NamesServerController.removeEntry);
//server controller
module.exports.removeEntry=function(req, res){
var abc=req.params.id;
var connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'test123',
database:'testing'
});
connection.connect();
connection.query('DELETE FROM NamesTable WHERE id= ?', [req.params.id],function(err,result){
if(err) throw err;
console.log(result);
});

<div ng-controller="NameController">
<ul>
<li ng-repeat='name in Names'>
<p> {{name.id}}</p>
<button ng-click=remove(name.id,$index)>remove</button>
</li>
</ul>
&#13;
答案 0 :(得分:0)
您需要向请求发送回复。通常使用空主体和204状态代码来响应DELETE请求:
res.send(204);