Skip to content

Instantly share code, notes, and snippets.

@vsergeyev
Created January 13, 2013 19:49
Show Gist options
  • Save vsergeyev/4525875 to your computer and use it in GitHub Desktop.
Save vsergeyev/4525875 to your computer and use it in GitHub Desktop.
Ajax upload of file with bootbox popup
bootbox.upload("Choose file", "/file_upload/", function($form) {
if (!$form) return;
var form_data = new FormData();
form_data.append("file", $form.find("input[type='file']")[0].files[0]);
$.ajax({
url: $form.attr("action"),
processData: false, // Important!
contentType: false, // Important!
data: form_data,
type: $form.attr("method"),
success: function(data, text) {
data = JSON.parse(data);
console.log("File uploaded");
},
error: function() {
console.log("Server error or no connection. Please try again.");
}
});
});
}
@danielandross
Copy link

Top!

@jeanie77
Copy link

jeanie77 commented Oct 17, 2016

Hello vsergeyev, which 'bootbox.upload()' function are you referring to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment