javascript - How to grab data from a js script in Jade for Node.js? -


i trying grab client side info queried server side of post. working on friend button when clicked post's route file, not sure how grab user.id associated , send node.js.

here jade file includes loop has user.id of each person.

extends layout block content        div     legend search results     div#userresults     user in ufirstname          a(href='/user/#{user.id}')             p #{user.firstname} #{user.lastname}         button.addcontact add contact 

here route file: trying figure out put on other side of friendrequest:

exports.addcontactpost = function(req, res, err) {     user.findbyidandupdate(req.signedcookies.userid,{                 friendrequest: req.body.friendrequest             }, function(err) {                 if(err) {                     console.log("post2");                     return console.log('error');                     //return res.render('addcontacterror', {title: 'weblio'});                   }                   else {                     console.log('postsuccess');                     alert('contact added');                  }              }); }; 

this script file trying magic:

 //add friends      $('.addcontact').click(function() {     $.post('/addcontact',        {friendrequest: $(this).data('user')});      if($(this).html!=='contact requested') {         return $(this).html('contact requested');     }     });   

i store id in add contact link:

button.addcontact(data-user=user.id) add contact 

amnd in handler

$('.addcontact').click(function() {     $.post('/addcontact',     {        friendrequest: $(this).data('user');     }      // ... } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -