Tuesday, 15 February 2011

javascript - jQuery .ajax POST request has an empty body when received by Node -



javascript - jQuery .ajax POST request has an empty body when received by Node -

for reason when create ajax post using jquery, body, received node empty. here ajax post:

jquery

var formdata = { 'order': order, 'words': 'words' }; $.ajax({ type: 'post', url: 'https://example.com/charge', processdata: false, data: json.stringify(formdata), contenttype: 'json', xhrfields: { withcredentials: false }, headers: { }, success: function (data) { console.log('success'); console.log(data); }, error: function () { console.log('we sorry our servers having issue right now'); } })

and here node code:

node

app.js

app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: false })); app.use('/', routes);

routes/index.js

router.post('/charge', function(req, res) { console.log(req.body); } //this logs {}

i have no thought doing wrong here. browser shows payload , post request (the formdata object) node logs nothing. ideas?

use ajax request this:

$.ajax({ type: 'post', url: 'https://example.com/charge', data: formdata, xhrfields: { withcredentials: false }, headers: { }, success: function (data) { console.log('success'); console.log(data); }, error: function () { console.log('we sorry our servers having issue right now'); } })

javascript jquery ajax node.js

No comments:

Post a Comment