AJAX 上传文件

AJAX上传不了文件

如果需要无刷新上传文件,请使用隐藏的iframe来代替

 

IFRAME:

 

<iframe frameborder="0" scrolling="no" resizable="no" allowtransparency="true" cellspacing="0" border="0" style="border: 0px none; height: 30px; width: 100%;" src="/attachments/new"></iframe>
 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link href="http://www.iteye.com/stylesheets/attachment.css?1272259777" media="screen" rel="stylesheet" type="text/css" />
    <script src="http://www.iteye.com/javascripts/application.js?1263904280" type="text/javascript"></script>
  </head>
  <body>
    <form action="/attachments" enctype="multipart/form-data" id="attachment_form" method="post">      <input id="attachment_uploaded_data" name="attachment[uploaded_data]" οnchange="upload(this.value);" size="30" type="file" /> <span id="spinner" style="display:none;">上传中 <img alt="Spinner" src="http://www.iteye.com/images/spinner.gif?1230301943" /></span>

    </form>
    
    <script type="text/javascript">
      if(document.location.host != "www.iteye.com") document.domain = "iteye.com";
      function upload(fileName) {
        if (!$A(['jpg','jpeg','bmp','png','gif','rar','zip', 'tar', 'gz', 'jar', 'war', 'bz2', 'pdf']).any(function(extName){return new RegExp('\\.'+extName+'$','i').test(fileName);})){
          alert("如果您上传图片,请上传png, jpg, gif或者bmp格式的图片\n如果您上传附件,请先压缩再上传");
          return false;
        }        
        var counter = parseInt(window.parent.$('attachments_counter').value) + 1;
        window.parent.$('attachments_counter').value = counter;
        window.parent.$('submit_button').value = counter + " 个文件正在上传中,请等待完成后再提交";
        $('spinner').show();        
        var iframes = window.parent.$("attachment_iframes");
        iframes.appendChild(iframes.getElementsByTagName('iframe')[0].cloneNode(false));
        $('attachment_form').submit();
      }
    </script>
  </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值