kianoush dortaj
kianoush dortaj

Reputation: 451

delete request in nodejs and ejs

i have a list and i need to send requet for delete item in nodejs and mongo , but i have a problem with request .

for send delete request i use the module method-override .

when i send the request it show me this error :

<form method="POST" action="/admin/course/<%- course._id %>?_method=DELETE">
                    <input type="hidden" name="_method" value="delete">
                   <button type="submit">
                    <a

                    class="btn-floating btn-small waves-effect waves-light red"
                    ><i class="material-icons">edit</i></a
                  >
                   </button> 
</form>

and in the js file i config that :

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

but it show me this error :

Cannot DELETE /admin/course/5eeb5b6afa7d0081e93d56d6

and this the route for delete :

admin =>

router.use('/admin',adminAuthntication.Handler, adminRouter);

admin =>

router.use('/course',courseRouter);

course =>

router.delete('/:id', courseController.Delete);

now whats the problem ? how can i solve this problem ???

Upvotes: 0

Views: 1603

Answers (1)

Alexandre
Alexandre

Reputation: 36

I used with full path at router and it works fine.

router.delete("/admin/course/:id", (request, response) => {
    const courseId = request.params.id;

Upvotes: 2

Related Questions