DELETE method using href - NodeJS

1

I'm loading some information from the database and one of the columns will be a link that will delete an information.

Being on a table, the href of the link looks like this:

href="#">#                    
asked by anonymous 30.09.2016 / 19:20

2 answers

0

I ended up doing it this way:

                <a href="javascript:void(0)" onClick="ExcluirRegistro('/stormtroppers/',{{stormtropper.id}})">Delete</a>

javascript:

function ExcluirRegistro(url, user_id) {
if (confirm('Deseja excluir o registro?')) {
    $.ajax({
        url: url + user_id,
        type: 'DELETE',
        success: function (res) {
            window.location.reload();
            return false;
        },
        error: function (xhr, status, error) {
            console.log(xhr.responseText);
            alert("Error deleting");
            return false;
        }
    });
}

}

Even so ... thanks for the info!

    
04.10.2016 / 17:33
0

When href is used, the browser uses the GET method to make the request. In the documentation for the module method-override it is written that, by default, the only HTTP method it overrides is POST . In order for the module to do what you need, you will need to pass the methods you want to override to the module. Change the following line:

app.use(methodOverride('_method'));

To:

app.use(methodOverride('_method', {methods: ['GET']}));

If you want to keep POST , just add the string 'POST' to the allowed methods array of the module.

    
03.10.2016 / 20:18