Last active
March 17, 2020 08:13
-
-
Save aonurdemir/04884bc2a0eda229a2560d35344f0470 to your computer and use it in GitHub Desktop.
File Upload with other post parameters by ajax
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
$(document).on("click", "#button-send", function () { | |
const payload = new FormData(); | |
payload.append("param1", $("#param1").val()); | |
payload.append("file",$('#photo-url')[0].files[0]); | |
$.ajax({ | |
url: "<URL>", | |
type: 'POST', | |
data: payload, | |
processData: false, // tell jQuery not to process the data | |
contentType: false // tell jQuery not to set contentType | |
}).done(function (response) { | |
//do something | |
}).always(function (e) { | |
//do something | |
}); | |
}); |
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
<input id="photo-url" type="file"> | |
<textarea id="param1" placeholder="Enter body text"></textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment