解决uploadify对象不支持此属性或方法

本文介绍了一种解决使用uploadify插件时出现的“对象不支持此属性或方法”错误的方法。问题源于JS调用Flash方法时机不当,通过调整至window.onload之后调用得以解决。

在做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对象生成后再初始化上传内容。
到此问题解决!

Code:
  1. window.onload=function(){
  2. $("#d2_Document").uploadify({
  3. 'uploader':'<%=ResolveClientUrl("~/Scripts/UploadFile/uploadify.swf")%>',
  4. 'script':'Uploadify.ashx?action=upload',
  5. 'cancelImg':'../../Scripts/UploadFile/cancel.png',
  6. 'folder':'../../uploads',
  7. 'fileExt':fileExt,
  8. 'fileDesc':'不支持的文件类型',
  9. 'sizeLimit':1024*1024*10,//10M
  10. //'buttonText':'SelectFiles',
  11. 'multi':false,
  12. onComplete:function(event,ID,fileObj,response,data){
  13. //将服务器的url通过wcf保存到数据库
  14. varresponseData=jQuery.parseJSON(response)
  15. if(responseData.result){
  16. varfile=fileObj.name;
  17. varsize=fileObj.size;
  18. varurl=responseData.file;
  19. addDocument(file,url,size);
  20. }
  21. }
  22. });
  23. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值