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(键值对)形式 提交,每一组数据以&分割

link:https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1

info[name]=hury&info[age]=40

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.