node.js - Why is the body of request empty? -
i'm using pattern project sending json-data node. in other project works, in project not. req-object valide, body empty. why?
client-side:
json = { "auth_user_pkref": 2 } json.test_id = "anca" json.questions_count = 3 json.right_answers = 2 json.wrong_answers = 1 json.seconds_spent = 180 console.log('/api/answer/add', json); $.ajax({ url: "/api/answer/add", type: "post", data: json.stringify(json), contenttype: "application/json", success: function (data) { }, error: function (jqxhr, textstatus, errorthrown) { console.log("error, db error"); } });
server-side:
router.post('/api/answer/add', function (req, res) { console.log('/api/answer/add: ', req.body)
server-log:
/api/answer/add: undefined
json = { "auth_user_pkref": 2 } json.test_id = "anca" json.questions_count = 3 json.right_answers = 2 json.wrong_answers = 1 json.seconds_spent = 180 console.log('/api/answer/add', json); $.ajax({ url: "/api/answer/add", type: "post", data: json, contenttype: "application/json", success: function (data) { }, error: function (jqxhr, textstatus, errorthrown) { console.log("error, db error"); } });
try this
Comments
Post a Comment