2016-08-12 26 views
2

我想从我的bd中删除一行恢复id。但是没有任何东西被删除。我在http中发送了id。 我没有错误代码,但我有一个印象,服务器端它不检索我发给他的ID。我无法恢复在我的服务器Express Js删除我的BD

我在我的服务代码角:

function removeTask(id){ 
    var promise = $http({ 
     method: "DELETE", 
     url: GENERAL_CONFIG.API_ENDPOINT + "todos", 
     data: id 
    }).then(function success(response) { 
     return response.data; 
     console.log(promise) 

    }, function error(response) { 
     //$rootScope.token = ""; 
     //$location.path("/home"); 
    }); 
    console.log(id); 
    return promise; 
} 

我在我的服务器代码快递JS:

Index.js : 

router.delete('/', function(req,res){ 
    console.log(req.body); 
    var updatePromise = service.removeTodoList(req.body); 
    updatePromise.catch(function(){ 
     res.sendStatus(500); 
    }); 
    updatePromise.then(function(rows){ 
     res.sendStatus(200); 
    }); 
}); 

Service.js : 


todoService.removeTodoList = function removeTodoList (id){ 
    var taskValues = id ; 
    console.log(id); 
    return dbHandler.query('DELETE FROM todolist WHERE id=?;',[taskValues]); 
} 

回答

0

我觉得你的端点URL是url: GENERAL_CONFIG.API_ENDPOINT + "todos", 而在index.js您使用router.delete('/', function(req,res){ 它应该是router.delete('/todos', function(req,res){

+0

如果我添加: router.delete( '/待办事项',函数(REQ,RES){ VAR updatePromise = service.removeTodoList(req.body); updatePromise.catch(function(){ res.sendStatus(500); }); updatePromise.then(function(rows){ res.sendStatus(200); }); }); 我是404错误! –

0

使用

$http({ 
    method: "DELETE", 
    url: GENERAL_CONFIG.API_ENDPOINT + 'todos/' + id 
}) 

而且

router.delete('/:id', function(req,res){ 
    console.log(req.params.id); 
    var updatePromise = service.removeTodoList(req.params.id); 
    updatePromise.catch(function(){ 
     res.sendStatus(500); 
    }); 
    updatePromise.then(function(rows){ 
     res.sendStatus(204); 
    }); 
}); 
相关问题