详解jquery uploadify 上传文件 |
网上找了一天,大家都说Uploadify唯一的缺点就是不支持中文按钮,杯具之前,我看了下Uploadify的API,才发现了几个参数没被大家提及的,这正是解决此问题的关键 。(以后坚决养成没事就看API的习惯) Uploadify还自带了很多参数及有用的方法和回调函数,都在API里,虽然是全英文的,但很容易看懂,这里就不说了 。 复制代码 代码如下: <script type="text/javascript"> $(document).ready(function() { $("#uploadify").uploadify({ uploader :images/uploadify.swf, script :<%=request.getContextPath()%>/content/ImportScheduleCommitAction.do, cancelImg : images/cancel.png, folder : /, queueID : fileQueue, fileDataName : uploadify, fileDesc : 支持格式:xls., fileExt : *.xls, auto :false, multi :true, height : 20, width : 50, simUploadLimit : 3, //buttonText : fdsfdsf..., buttonImg : images/browse.jpg, // hideButton : true, // rollover : true, wmode : transparent, onComplete : function (event, queueID,fileObj, response, data) { $(<li></li>).appendTo(.files).text(response); }, onError : function(event,queueID, fileObj) { alert("文件:"+ fileObj.name + " 上传失败"); } // onCancel : function(event,queueID, fileObj) // { // alert("取消文件:" +fileObj.name); // } }); <script type="text/javascript"> $(document).ready(function() { $("#uploadify").uploadify({ uploader : images/uploadify.swf, script :<%=request.getContextPath()%>/content/ImportScheduleCommitAction.do, cancelImg : images/cancel.png, folder : /, queueID : fileQueue, fileDataName : uploadify, fileDesc : 支持格式:xls., fileExt : *.xls, auto : false, multi : true, height : 20, width : 50, simUploadLimit : 3, //buttonText : fdsfdsf..., buttonImg : images/browse.jpg, // hideButton : true, // rollover : true, wmode : transparent , onComplete : function (event, queueID,fileObj, response, data) { $(<li></li>).appendTo(.files).text(response); }, www.th7.cn onError : function(event,queueID, fileObj) { alert("文件:"+ fileObj.name + " 上传失败"); } // onCancel : function(event,queueID, fileObj) // { // alert("取消文件:" + fileObj.name); // } }); 要注意的是,我的script属性值是一个请求路径,我发现在我设置了同时上传多个文件后(比如3),并不是每请求一次去上传3个文件,而仍然是执行3次请求,请求一次上传一个文件 。这也没办法,uplodify有那么多回调函数,要是一次处理多个,那回调函数的参数就不知道拿哪个了,因为这些参数都不是数组 。 也就是说,无论你设置同时上传几个文件,它都会一个一个去请求并上传,只是表面上感觉好像有多个线程同时在处理上传请求一样,只是表象而已 。而且如果你把simUploadLimit设置过大就会经常出错,我设置成5的时候经常会有一两个文件上传失败 。 |