Skip to content

Instantly share code, notes, and snippets.

@toranb
Created November 11, 2012 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toranb/4056283 to your computer and use it in GitHub Desktop.
Save toranb/4056283 to your computer and use it in GitHub Desktop.
cross domain multipart post for file upload
var iframeId = 'somethingUnique';
var url = 'http://someotherdomain.com';
var $form = $('<form>');
$form.attr('id', 'foo');
$form.attr('action', url);
$('<iframe name="' + iframeId + '" id="' + iframeId + '" />').appendTo('body');
$("#" + iframeId).attr('style', 'display: none;');
$("#" + iframeId).append($form);
$form.attr('target', iframeId);
$form.attr('method', 'POST');
$form.attr('enctype', 'multipart/form-data');
$form.attr('encoding', 'multipart/form-data');
$form.submit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment