Ali Zia
Ali Zia

Reputation: 3875

Converting data into JSON

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?

enter image description here

Upvotes: 0

Views: 1462

Answers (1)

Siddu
Siddu

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

Related Questions