node.js - Data is been sent from client but not reached in server angular2 and nodejs -


i trying post form data server(node) not getting reached there when put console data in backend says undefined.data been sent client not reached in server.i think wrong @ headers,can 1 please suggest help. ts,

    var headers = new headers();     headers.append('content-type', 'application/x-www-form-urlencoded')     this.http.post(this.header1+'login', json.stringify(form), { headers: headers }) 

my server,

exports.login = function( req, res ) {  console.log("params:"+req.body.email);   //console.log('email:'+params.email);   var query = 'select * profile email = ? , password = ?';   connection.query(query,[req.body.email,req.body.password],function(error,result,rows,fields){     if(!!error){console.log(error)       console.log('fail');     }else{       console.log(result);       res.send(result);     }   // }    });} 

my routes(express)

 router.post('/login', admin.login); 

http uses observable , observables lazy. don't execute unless subscribed to.

you need either

this.http.post(this.header1+'login', json.stringify(form), { headers: headers }) .subscribe(response => console.log(response.json());  this.http.post(this.header1+'login', json.stringify(form), { headers: headers }) .topromise(); 

to make http send request.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -