Last active
December 11, 2015 10:38
-
-
Save sesopenko/4587842 to your computer and use it in GitHub Desktop.
Example code for an ajax file upload with jQuery and HTML5.
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
if(window.FormData){ | |
var formData = new FormData($('form#uppic', $('div#upload'))[0]); | |
$.ajax({ | |
url:'/upload/'+gUUID, | |
type:'POST', | |
xhr:function(){ | |
var myXhr = $.ajaxSettings.xhr(); | |
if(myXhr.upload){//check if upload property exists | |
myXhr.upload.addEventListener('progress', sendpic.progressHandle); | |
} | |
return myXhr; | |
}, | |
success:sendpic.sendsuccess, //function that will receive unparsed string | |
error:sendpic.senderror, //function that will receive an error object | |
data:formData, | |
cache:false, //important | |
contentType:false, //important | |
processData:false //important | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment