Skip to content

Instantly share code, notes, and snippets.

@Shadowfiend
Created May 6, 2010 21:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Shadowfiend/392749 to your computer and use it in GitHub Desktop.
Save Shadowfiend/392749 to your computer and use it in GitHub Desktop.
// In cases where we have an AJAX request for IE with an uploaded file, we
// assume we served through an iframe (a fairly safe assumption) and serve
// up the response with a content type of text/plain so that IE does not
// attempt to save the file.
LiftRules.responseTransformers.append {
resp =>
(for (req <- S.request) yield {
resp match {
case InMemoryResponse(data, headers, cookies, code)
if ! req.uploadedFiles.isEmpty &&
req.isIE &&
req.path.wholePath.head == LiftRules.ajaxPath =>
InMemoryResponse(data, ("Content-Type", "text/plain; charset=utf-8") :: headers, cookies, code)
case _ => resp
}
}) openOr resp
}
$(document).load(function() {
var iframe =
$('<iframe name="upload-iframe" />')
.css('display', 'none')
.load(function() {
$.globalEval($(this).contents().text());
setupForm();
});
$('body').append(iframe);
function setupForm() {
$('#form-wrapper form')
.attr('target', 'upload-iframe')
.removeAttr('onsubmit')
.attr('action', '/ajax_request/' + lift_page)
.attr('method', 'post')
.attr('encoding', 'multipart/form-data')
.attr('enctype', 'multipart/form-data')
.find('input:submit, button[type=submit]')
.removeAttr('onclick')
.end()
.append($('<input type="hidden" name="' +
$('#form-wrapper form').find('input:submit, button[type=submit]').attr('name') +
'" value="_" />'))
});
setupForm();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment