Ali Zia Ali Zia - 5 months ago 38
JSON Question

Converting data into JSON

I have a node server. It takes ajax calls and uses the data in this format.


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?

enter image description here


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()+'"}}';