在做Ajax上传时uploadify(v2.1.4)是非常不错的JQuery插件,昨天在家做了好好的页面,到了单位发现总是报“对象不支持此属性或方法”错误,具体出错在“document.getElementById(jQuery(this).attr('id') + 'Uploader').startFileUpload(ID, checkComplete);”,网上查了很多帖子都没有解决。
想了半天,应该是js调用flash方法时调用失败,查了相关帮助,js调用flash必须在window.onload之后调用。此时豁然开朗!
之间我在$(function(){...});中初始化,$相当于document.onready(),此时flash还没有被加载进来,而在window.onload页面完全加载完毕,dom对象生成后再初始化上传内容。
到此问题解决!
- window.onload=function(){
- $("#d2_Document").uploadify({
- 'uploader':'<%=ResolveClientUrl("~/Scripts/UploadFile/uploadify.swf")%>',
- 'script':'Uploadify.ashx?action=upload',
- 'cancelImg':'../../Scripts/UploadFile/cancel.png',
- 'folder':'../../uploads',
- 'fileExt':fileExt,
- 'fileDesc':'不支持的文件类型',
- 'sizeLimit':1024*1024*10,//10M
- //'buttonText':'SelectFiles',
- 'multi':false,
- onComplete:function(event,ID,fileObj,response,data){
- //将服务器的url通过wcf保存到数据库
- varresponseData=jQuery.parseJSON(response)
- if(responseData.result){
- varfile=fileObj.name;
- varsize=fileObj.size;
- varurl=responseData.file;
- addDocument(file,url,size);
- }
- }
- });
- }
本文介绍了一种解决使用uploadify插件时出现的“对象不支持此属性或方法”错误的方法。问题源于JS调用Flash方法时机不当,通过调整至window.onload之后调用得以解决。
1568

被折叠的 条评论
为什么被折叠?



