Advertisement
vamsiampolu

Express body parser

Oct 28th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. I have this code on the client side:
  2.  
  3. var dataObj={
  4.         title:title
  5.     };
  6.     var dataJSON=JSON.stringify(dataObj);
  7.     $.ajax({
  8.         type:'POST',
  9.         url:'/notebook/',
  10.         data:dataJSON
  11.     }) 
  12.     .done(function(data){
  13.         console.log("Notebook has been created");
  14.     });
  15.  
  16. I have this code(using express bodyParser)
  17.  
  18. router.post('/',function(req,res){
  19.     console.log(req.body);//
  20.     console.log(req.body.title);
  21.     /*var nb=new notebook({
  22.         title:req.body.title,
  23.         isActive:false
  24.     });
  25.     nb.save(function(err,doc){
  26.         if(err)
  27.             console.error(err);
  28.         else
  29.         {
  30.             console.log("Notebook Document has been saved");
  31.             console.log(doc);
  32.         }  
  33.     });*/
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement