Why can’t express parse the data from ajax post?

  node.js, question

Jquery.ajxpost submits an object

Print out req.body, and the result is this

What is the reason? Synchronous submission with form forms can be resolved normally

jQuery.ajaxSend data by defaultcontentTypeYesapplication/x-www-form-urlencoded

application/x-www-form-urlencodedThe standard requirements are as follows

  1. nameAndvalueBoth mustescaped,SpacesUseAddReplace

  2. In the order in the documentnames/values(键值对)形式 提交,每一组数据以&分割



The data asked by the landlord,post.bodyAs above, the analysis is completely correct.Key value pairOnly one level, and allKeyAll are equal and there are no sub-elements.

If you want the submitted data to be directly parsed into objects, you can refer to other answers.body-parser formidableSuch as component analysis.

Commonly usedcontentTypein addition

  • multipart/form-dataUpload file

  • text/plainNative data has not been processed, and the parsing method can be customized.