Reputation: 3875
I have a node server. It takes ajax calls and uses the data in this format.
{"action":"login","data":{"uname":"fas4","password":"jaltheband"}}
I am using a local ajax call and converting my username and password in this format but when I console.log req.body, it shows me a strange format. This is how I am converting data in JSON.
var data = '{"action":"login","data":{"uname":"'+$("#username").val()+'","password","'+$("#password").val()+'"}}';
And then I console.log(req.body), this is displayed.
The formats are different. Why is that so?
Upvotes: 0
Views: 1462
Reputation: 136
After the "password" key, a double quote followed by colon is missing and the comma is misplaced, try this -
var data = '{"action":"login","data":{"uname":"'+$("#username").val()+'","password":"'+$("#password").val()+'"}}';
Upvotes: 1