Created
May 6, 2010 21:57
-
-
Save Shadowfiend/392749 to your computer and use it in GitHub Desktop.
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
// 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 | |
} |
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
$(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