Thursday, 13 April 2017

Trying To Delete MongoDB Document In Ajax Keep Getting Error 404 'CANNOT DELETE'

So I want to be able to delete a specific item in my MongoDB when I click on a button using the "gameName" value. When I do this I keep getting error 404 'Cannot Delete'. What I am doing wrong here? Thank you.

Here is the request:

function deleteGame() {
$('#js-games').on('click', '.delete', function(event) {
    event.preventDefault();
    console.log('delete button works')
    var id = $(this).parent().data('id');
    console.log(id);
$.ajax({
    type: 'DELETE',
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    url: '/favorites' + '/' + id,
    success: getYourGames(),
})
    var gone = 'Your time was deleted!';
    $('.js-type-game').html(gone);
    setTimeout(function() {
        $('.js-type-game').fadeOut(gone).html('').fadeIn();
        }, 2000);
})

}

And here is the router.delete:

router.delete('/gameName', (req, res) => {
favorite.delete(req.params.gameName);
console.log(`Deleting game \`${req.params.gameName}\``);
res.status(204).end();
});



via JontheNerd

No comments:

Post a Comment