search

Home  >  Q&A  >  body text

javascript - Problems with jquery's ajax post data

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

仅有的幸福仅有的幸福2787 days ago679

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-17 09:18:00

    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)
      }
    })

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-17 09:18:00

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

    reply
    0
  • Cancelreply