I want a consume a rest call which is written in node js of POST type.I requires two headers namely name and location of type application/x-www-form-urlencoded .Now I want to consume this using $http in my angular js application.I tried the below code
var ename = name;
var eloc = location;
var config = {
headers:{
'Content-Type':'application/x-www-form-urlencoded;charset=utf-8;'
}
}
var data = {
name:ename,
location:location
};
$http.post('/addemp',data
,config)
.success(function (status, headers, config) {
console.log(status);
});
But those two name and location are taken as null in my rest call.How can we pass this..Below is my node js rest call
app.post('/addemp',function(req,res){
con.query(insertdata,[req.body.name,req.body.location],function(err,res){
// if(err)
throw err;
console.log("Inserted",err);
//con.end();
});
res.send("record inserted with id");
});
var insertdata = "insert into employees(name,location) values(?,?)";
The values in db are getting inserted as null.Please Can some help me how to work here.
via user7350714
No comments:
Post a Comment