javascript - Problems with jquery's ajax post data
仅有的幸福
仅有的幸福 2017-06-17 09:16:00
0
2
595

This is the frontend ajax method

This is the contents of files before transmission

This is the content received by the background req.body after submission

May I ask why files are automatically traversed and output? I didn't do anything else, I just wanted to return the files as a whole to the background

仅有的幸福
仅有的幸福

reply all (2)
我想大声告诉你

When data is transmitted, it is spliced in the form of key/value. The value of value must be a string. If it is a complex object ({}/[]), it will be traversed and split into the smallest units to satisfy the key/value pair. . It is recommended that you convert the files value into string (JSON.stringify(files)), and then convert it back (JSON.parse()) after receiving the data in the background.

$.ajax({ url:'xxx', type: 'post', dataType: 'json', data: { title: title, belongTo: belongTo, content: content, files: JSON.stringify(files) } })
    曾经蜡笔没有小新

    That’s it, no problem, what is received in the background is the entire files.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!