Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this ts code to add brand to database table:

TypeScript
add_brand(bDesc,captionid){
     console.log(bDesc);     ***print correct value***
     this.http.post("http://localhost:3000/add_Brand",{bDesc,captionid}).subscribe(
     (res) => {
       console.log("record INSERTEDw");                                             //working True
       this.table.renderRows();
     },
     (error) => {console.log(error)}
     );
}

and in nodejs recive parameters from above ts code:

JavaScript
const bodyParser=require('body-parser');


app.post("/add_brand",(req,res)=>{
    console.log(req.body.bdesc);                        ***print undefined***
    const insertquery="INSERT INTO brandtbl (BDesc,CaptionCode) VALUES ('" + req.body.bdesc + "'," + req.body.captionid + ")";
    
    ConnectToDB().query(insertquery,(err,result)=>{

       if (err){
           console.log("error"+err);
           res.sendStatus(500); 
           return;
       }
       else{
       console.log("record inserted");
       res.end();}
   })
});

but for bDesc i recive undefined value ,how to change to recive string correct value?

What I have tried:

Quote:
this.http.post("http://localhost:3000/add_Brand",{bDesc,captionid}).subscribe
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900