javascript - FormData()的兼容性,如何在IE8中使用,或者有没有其他替代方法,大神快来!!
大家讲道理
大家讲道理 2017-04-10 17:58:16
[JavaScript讨论组]

FormData()的兼容性,如何在IE8中使用,或者有没有其他替代方法,大神快来!!

<form id="fileForm" class="form-horizontal" action="<c:url value='/excelimp/form.shtml'/>" enctype="multipart/form-data" method="post"  role="form">
    <p class="modal-dialog">
        <p class="modal-content">
            <p class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h3 id="fileModalLabel">批量导入</h3>
            </p>
            <p class="modal-body">
                <p class="control-group control_group_heigth margintop10" style="margin-left:0px;">
                    <label class="control-label span5 text-right">Excel文件:<i class="require_star">*</i></label>
                    <label ><input type="file" name="file"  required="required" id="Excelfile"/></label>
                </p>
            </p>
            <p class="modal-footer">
                <p id="fileloadingtip" class="control-group" style="display:none;margin-right:90px;margin-bottom:0px;">
                    <img style="height: 20px;width:20px;" src="<c:url value='/img/common/loading.gif'/>">
                    <span style="font-size: 12px;">操作处理中,可能需要几分钟时间,请稍候。。。</span>
                </p>
                <button type="button" class="btn btn-primary" id="btn_imp" name="btn_imp">导入</button>
                <button type="button" class="btn" data-dismiss="modal" name="btn_cancel">取消</button>
            </p>                              
        </p>
    </p>
</form>

后面用了new FormData()来传给后台数据,结果在IE下出现FormData未定义的问题,请问有没有什么兼容的解决方法或者替代方法

$("#btn_imp").on('click', function(e) {
        var formData = new FormData($( "#fileForm" )[0]);
         $.ajax({  
              url: $( "#fileForm" ).attr('action'),  
              type: 'POST',  
              data: formData,  
              async: false,  
              cache: false,  
              contentType: false,  
              processData: false,  
              success: function (data) {  
                        alert("导入成功");
              },  
              error: function (data) {  
                  $("#errorinfo").html(data.msg);
              }  
         });           
        return false;
    });
});
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(3)
PHP中文网

已经找到解决办法了,用jquery.form插件中的ajaxSubmit可以支持文件的上传

巴扎黑

jQuery.serialize() 序列化表单值。

ringa_lee

jquery.form 有时候用起来很尴尬

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号