I keep getting [object][Object] as my request from a form with a POST request method while using node.js

前端 未结 1 1101
甜味超标
甜味超标 2021-01-28 11:50

I have been trying to get the value of my text input in a form with a POST request, but on the server side, the req.body is returning a [objecet][Object]

相关标签:
1条回答
  • 2021-01-28 12:27

    The automatic string conversion in Javascript for an object is just [Object][object] so when you do this:

    console.log('The task is '+ req.body)
    

    that's what is happening. req.body undergoes an automatic string conversion to [Object][object] and that's appended to your string.

    To fix, change your code to this:

    console.log('The task is ', req.body);
    

    so that console.log() can output the whole req.body object.

    0 讨论(0)
提交回复
热议问题