Skip to content

Instantly share code, notes, and snippets.

@aonurdemir
Last active March 17, 2020 08:13
Show Gist options
  • Save aonurdemir/04884bc2a0eda229a2560d35344f0470 to your computer and use it in GitHub Desktop.
Save aonurdemir/04884bc2a0eda229a2560d35344f0470 to your computer and use it in GitHub Desktop.
File Upload with other post parameters by ajax
$(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
});
});
<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