通过ajax Excel导入
来源:互联网 发布:php电子商务网站 编辑:程序博客网 时间:2024/06/05 08:08
使用FormData,进行Ajax请求并上传文件
这里使用JQuery,但是老版本的JQuery比如1.2是不支持的,最好使用2.0或更新版本:
注:
如上,通过$('#postForm').serialize()可以对form表单进行序列化,从而将form表单中的所有参数传递到服务端。
但是上述方式,只能传递一般的参数,上传文件的文件流是无法被序列化并传递的。
不过如今主流浏览器都开始支持一个叫做FormData的对象,有了这个FormData,我们就可以轻松地使用Ajax方式进行文件上传了。
- <div class="modal fade bs-example-modal-sm1" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm1">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel2">机器信息导入</h4>
</div>
<div class="modal-body">
<form id="excelImportForm">
<table class="table table-striped table-bordered dataTable no-footer">
<tbody>
<tr>
<td style="text-align: center;font-size:20px;font-weight:700">文件</td>
<td><input type="file" name="fileName"/></td>
<td><input type="hidden" name="type" value="machInfo"/></td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" id="cancelId">取消</button>
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="machInfoImport()">导入</button>
</div>
</div>
</div>
</div>
-
function machInfoImport(){ var formData= new FormData($("#excelImportForm")[0]); $.ajax({ type:'POST', url:'/fudaMes/excel/importExcel', data:formData, async: false, cache: false, contentType: false, processData: false, //必须要 success: function (data) { if(data=="success"){ new PNotify({ title:'导入成功', text: '机器信息导入成功', type: 'success', styling: 'bootstrap3' }); }else{ new PNotify({ title:'导入失败', text: ''+data, type: 'error', styling: 'bootstrap3' }); } $(".modal-backdrop").remove(); $("body").removeClass('modal-open'); $('body').removeAttr("style") $('body').css('display','block'); load_orderInfo(); }, error: function (data) { console.log(JSON.stringify(data)) } }); }
阅读全文
1 0
- 通过ajax Excel导入
- 通过ajax上传excel
- Ajax asp.net 导入Excel
- WEB表格通过Excel.Application导入excel.
- Java 通过 ajax导出excel
- JS读取Excel资料AJAX导入
- 【NPOI】Ajax异步导入Excel文件
- ajax上传excel文件导入数据
- 通过Javascript把页面导入到Excel
- 通过上传excel导入数据到数据库
- asp.net通过excel批量导入
- Excel数据通过plsql 导入到Oracle
- 通过PL/SQL导入excel文件
- 通过excel导入导出oracle中数据
- 通过PL/SQL导入excel文件
- Excel数据通过plsql导入到Oracle
- 通过PL/SQL导入excel文件
- PHP通过PHPExcel类导入excel
- ZOJ3881:From the ABC conjecture(莫比乌斯反演)
- 华为面试题一例
- 1230: [Usaco2008 Nov]lites 开关灯
- MVC4-View(视图)
- jQuery
- 通过ajax Excel导入
- Maven--本地中央厂库配置
- mac book air 安装win10
- ubuntu 下 配置nfs服务
- 【JVM】Java内存区域与OOM
- 微信扫码登录网页实现原理
- Junit单元测试遇到的initializationerror:method initializationerror not found
- rviz的简单使用
- YUV测试序列下载地址