-
-
Save billhorsman/4345379 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
$form.fileupload | |
dataType: "json" | |
done: (e, data) -> | |
result = if data.result? | |
# XHR (as used by, say, Chrome) gives you a simple JSON object | |
data.result | |
else | |
# iframe (as used by IE) gives you text back that you'll want to parse manually) | |
# Urgh. UTF8 value (passed by Rails form) causes JSON to fall over. Crappy solution on next line. | |
data = JSON.stringify(data).replace(/"name":"utf8","value":"[^"]*"/, '"name":"utf8","value":"REMOVED"') | |
JSON.parse(data).result | |
console.log result |
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
class MyController < ApplicationController | |
def my_action | |
# Do whatever you need to do | |
respond_to do |format| | |
format.js { | |
render json: to_json(@agent) | |
} | |
format.html { | |
# iframe won't use .js it will just appear as .html - fool the client into thinking they're getting proper json back. | |
render text: "<textarea data-type=\"application/json\">#{to_json(@agent)}</textarea>" | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some tweaks I had to make to get jQuery-File-Upload working with IE (without breaking other browsers in the process). See https://github.com/blueimp/jQuery-File-Upload