Created
May 18, 2017 08:22
-
-
Save LasseRafn/9323245af2857be003f471f4712b7cef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateFormData() { | |
// define upload field | |
let file_input = document.getElementById('profile_picture'); | |
// define form data | |
let data = new FormData(); | |
// Add regular text field | |
data.append("name", "John Doe"); | |
// If any files added to file_input, add first | |
if (file_input.files.length > 0) { | |
data.append('profile_picture', file_input.files[0]); | |
} | |
return data; | |
} | |
// Now simply post the generated form data using ajax. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment