Last active
August 29, 2015 14:00
-
-
Save sinfere/6df9fbf3310eafdca420 to your computer and use it in GitHub Desktop.
Simplest ajax upload file
This file contains hidden or 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
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