Ali Zia Ali Zia - 1 year ago 107
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

Answer Source

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()+'"}}';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download