Created
August 25, 2011 13:06
-
-
Save 4e4c52/1170604 to your computer and use it in GitHub Desktop.
Upload files via AJAX using FormData
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
UploadFile = (f) -> | |
xhr = new XMLHttpRequest() | |
if (xhr.upload) | |
xhr.open("POST", "/admin/assets.json", true) | |
xhr.setRequestHeader("X_FILENAME", f.name) | |
# new_asset is the ID of my <form> | |
data = new FormData(document.getElementById('new_asset')) | |
data.append("asset[picture]", f) | |
xhr.send(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment