2016-08-12 25 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); 
    }); 
}); 
相關問題