Home  >  Q&A  >  body text

javascript - How to submit a form with pictures using ajax post method

<form>
    <input name="xxxx" type="text">
    <input name="images" type="file" multiple="multiple" >
</form>

Because there are multiple pictures in the second form, how to submit the data of the above two forms together when submitting the form using ajax post method?

阿神阿神2711 days ago524

reply all(8)I'll reply

  • PHP中文网

    PHP中文网2017-05-18 11:01:29

    Use formData

    reply
    0
  • 阿神

    阿神2017-05-18 11:01:29

    Ask the backend! Generally, the key returned by uploading the image is given to the backend, and the form is defined by the backend.

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-18 11:01:29

    Use html5 to convert the image to BASE64, and then return it to the background through ajax. The background converts the image into the image format and stores it in the server through base64.
    You can refer to this textbook
    http://www.zhangxinxu.com/wor...

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-18 11:01:29

    When uploading images, base64 encoding is the correct solution.

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-18 11:01:29

    The above are all ideas, I provide a simpler method, using ajaxsubmit, plug-in

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-18 11:01:29

    Don’t convert to base64, it will increase by 1/3. Browsers that support drawing the image in the input onto the canvas and then fetching base64 must already support xhr2.0 or fetch API.

    reply
    0
  • 高洛峰

    高洛峰2017-05-18 11:01:29

    Create a formdata object, assign a value to the object, and submit the formdata object as ajax data.
    It is recommended to take a look at this
    http://www.ruanyifeng.com/blo...

    reply
    0
  • 为情所困

    为情所困2017-05-18 11:01:29

    Uploading files generally requires either direct form submission (but the entire page will be refreshed, and partial refresh can be achieved by embedding into an iframe), which will be parsed by the backend itself; or uploaded according to the w3c standard formData. Generally, plug-ins also use these two methods.

    reply
    0
  • Cancelreply