Reputation: 29
In angular 4 at a client side, i have a post method when i click on it ->
var json=JSON.stringify({id:"1",name:"par",title:"ssss"});
var params='json'+json;
this.http.post("http://localhost:3000/users/insertData",params, optio
.subscribe(res => console.log(res.json()));}
after click on this at server side, I am using node express js, so the problem at server side I am getting data that type which is not acceptable for the database my SQL so data is getting ->
{ 'json{"id":"1","name":"par","title":"ssss"}' : ' ' }
but I want to get data is ->only JSON form
{"id":"1","name":"par","title":"ssss"}
so please give me some solution ...
Upvotes: 1
Views: 210
Reputation: 4306
By default Angular converts all your form submission data into json, even if you submit a model it is converted to json before sending it to the server. Unless you explicitly want to submit form data.
Secondly as pointed out by Adam, what are you trying to achieve using this piece of code var params='json'+json;
Upvotes: 0
Reputation: 958
This line: var params='json'+json;
You are concatenating a string with some data in JSON form.
I am not sure what you are trying to do with that, but that is why the data is not JSON when you receive it on the back end.
Upvotes: 0
Reputation: 1026
Try without stringify
var params={id:"1",name:"par",title:"ssss"}
Upvotes: 1