jquery file upload without other plugin

<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"><title></title><script src=""></script></head><body><div><form enctype="multipart/form-data"><input name="file" type="file" /><input type="button" value="Upload" /></form><progress></progress></div><script>$(':file').change(function(){var file = this.files[0];var name = file.name;var size = file.size;var type = file.type;//Your validation});$(function(){$(':button').click(function(){var formData = new FormData($('form')[0]);$.ajax({url: '/excel', //Server script to process datatype: 'POST',xhr: function() { // Custom XMLHttpRequestvar myXhr = $.ajaxSettings.xhr();if(myXhr.upload){ // Check if upload property existsmyXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload}return myXhr;},//Ajax events//beforeSend: beforeSendHandler,//success: completeHandler,//error: errorHandler,// Form datadata: formData,//Options to tell jQuery not to process data or worry about content-type.cache: false,contentType: false,processData: false});});});function progressHandlingFunction(e){if(e.lengthComputable){$('progress').attr({value:e.loaded,max:e.total});}}</script></body></html>

reference url:

,明天的希望,让我们忘了今天的痛苦

jquery file upload without other plugin

相关文章:

你感兴趣的文章:

标签云: