Skip to content

Instantly share code, notes, and snippets.

@sinfere
Last active August 29, 2015 14:00
Show Gist options
  • Save sinfere/6df9fbf3310eafdca420 to your computer and use it in GitHub Desktop.
Save sinfere/6df9fbf3310eafdca420 to your computer and use it in GitHub Desktop.
Simplest ajax upload file
var data = new FormData();
data.append('file', src.files[0]);
$.ajax({
url: url,
type: 'POST',
data: data,
processData: false,
contentType: false,
xhr: function() {
var xhr = $.ajaxSettings.xhr();
if (xhr.upload)
{
xhr.upload.addEventListener('progress', function (event) {
console.log(event);
}, false);
}
return xhr;
},
success: function(data) {
console.log(data)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment