How to use FormData for AJAX file upload?

后端 未结 9 1359
不思量自难忘°
不思量自难忘° 2020-11-21 06:13

This is my HTML which I\'m generating dynamically using drag and drop functionality.

9条回答
  •  离开以前
    2020-11-21 06:58

    I can't add a comment above as I do not have enough reputation, but the above answer was nearly perfect for me, except I had to add

    type: "POST"

    to the .ajax call. I was scratching my head for a few minutes trying to figure out what I had done wrong, that's all it needed and works a treat. So this is the whole snippet:

    Full credit to the answer above me, this is just a small tweak to that. This is just in case anyone else gets stuck and can't see the obvious.

      $.ajax({
        url: 'Your url here',
        data: formData,
        type: "POST", //ADDED THIS LINE
        // THIS MUST BE DONE FOR FILE UPLOADING
        contentType: false,
        processData: false,
        // ... Other options like success and etc
    })
    

提交回复
热议问题