Saturday, 3 June 2017

How to perform jquery ajax delete operation when delete is to remove an entry in mongodb?

I have a sample nodejs app with api in mondodb connected via mongoose. I get a bunch of responses something like this (Sinple Entry below)

    {
    name:"Task1"
    status:["pending"]
    0:"pending"
    __v:0
    _id:"592d6a398eb24a9ac85d1184"
   }

Now If I have to delete the entry I will create a route like:

/tasks/_id

which I have created in nodejs and it works fine. I need perform a delete operation using an ajax delete operation. How do I create a route like /tasks/_id in ajax that will delete the record. Below is my code.

     $.ajax({
      type:'DELETE',
      url:'/tasks/' + how to get _id here from mongodb, which could be available only on successful ajax operation,

        success : function( data) {
          console.log('success);
       },
      error : function() {
        console.log('error');

      }
    })



via Mike

No comments:

Post a Comment