Skip to content

Instantly share code, notes, and snippets.

@joshefin
Created January 11, 2013 00:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshefin/4506897 to your computer and use it in GitHub Desktop.
Save joshefin/4506897 to your computer and use it in GitHub Desktop.
Multipart cross domain post request with ajax
var data = new FormData();
form.find("input, textarea").each(function() {
var input = $(this);
if (input.attr("type") == "file")
data.append(input.attr("name"), input[0].files[0]);
else
data.append(input.attr("name"), input.val());
});
$.ajax({
type: "POST",
url: "someurl",
data: data,
contentType: false,
mimeType: "multipart/form-data",
processData: false,
crossDomain: true,
cache: false,
success: function(post, textStatus, jqXHR) {
// ...
},
error: function(jqXHR, textStatus, errorThrown) {
// ...
},
complete: function(jqXHR, textStatus) {
// ...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment