jquery file upload without other plugin
2015-05-19 21:41
429 查看
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></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 data type: 'POST', xhr: function() { // Custom XMLHttpRequest var myXhr = $.ajaxSettings.xhr(); if(myXhr.upload){ // Check if upload property exists myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload } return myXhr; }, //Ajax events // beforeSend: beforeSendHandler, // success: completeHandler, // error: errorHandler, // Form data data: 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: http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously
相关文章推荐
- 在ASP.NET中实现多文件上传(三)---jQuery Multiple File Upload Plugin
- jQuery File Upload Plugin 出现uid is 503或者没有图片缩略图
- jquery multiple file upload plugin
- jquery multiple file upload plugin
- jQuery Multiple File Upload Plugin
- HTML5 File Upload Script, jQuery Multiple File Upload Plugin - Uploadify / UploadiFive - Uploadify
- 根据jquery-file-upload简单写的一个工程(针对之前的简单实用指南)
- jquery upload file
- jQuery 关于ajaxfileupload.js插件的逐步解析(ajaxfileupload.js第二弹)
- PHP结合jQuery插件ajaxFileUpload实现异步上传文件实例
- jQuery插件之ajaxFileUpload
- jquery.fileupload.js 杂记
- jQuery file upload的两种方式
- 前端上传插件,uploadive和jquery file-upload,选择哪一个?
- jquery之ajaxfileupload异步上传插件
- Jquery+ajaxfileupload上传文件
- jquery file upload报错 TypeError: Object [object Object] has no method 'progressbar'
- jQuery插件之ajaxFileUpload
- ajaxFileUpload plugin上传文件 chrome、Firefox中出现SyntaxError:unexpected token <
- 分享2个jQuery插件--jquery.fileupload与artdialog