Created
January 11, 2013 00:11
-
-
Save joshefin/4506897 to your computer and use it in GitHub Desktop.
Multipart cross domain post request with 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
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