日期:2014-05-16 浏览次数:20828 次
<%@ page contentType="text/html;charset=GBK" language="java" %> <!DOCTYPE html> <html> <head> <title>导入</title> <link href="css/bootstrap.min.css" rel="stylesheet"> <script src="js/jquery-1.8.2.min.js"></script> <script src="js/jquery.form-3.26.0.js"></script> <script src="js/jquery.validate.min-1.7.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/bootstrap.file-input.js"></script> </head> <body> <div class="container"> <h3>导入Excel</h3> <form id="uploadimg-form" action="" method="post"> <input type="file" title="上传" name="fileUpload" id="fileUpload"/><br /><br /> <input id="fileBtn" type="submit" class="btn" value="文件上传"/><br /><br /> </form> <div id="showData" style="display: none;"> <div> <p>导入数据如下:</p> <p id="jsonShow"></p> </div> </div> </div> <script type="text/javascript"> $(function() { $("#uploadimg-form").resetForm().validate({ rules: { "fileUpload": { required: true, accept: "xls" } }, messages: { "fileUpload": { required: "请选择上传文件", accept: "文件格式不支持,请上传 xls 格式的文件" } }, submitHandler: function() { $("#uploadimg-form").ajaxSubmit({ url:"ajax.jsp?m=uploadExcel", type:"post", enctype:"multipart/form-data", contentType: "application/x-www-form-urlencoded; charset=utf-8", dataType:"json", success: function(data){ var str = ""; for (var i=0, len=data.length; i < len; i++) { str += "<p>"; str += data[i]["deparement"] + "," + data[i]["name"] + "," + data[i]["date"]; str += "</p>"; } $("#jsonShow").append(str); $("#showData").removeAttr("style"); $("#jsonBtn").removeAttr("disabled").removeAttr("title"); }, error: function() { alert('error'); } }); return false; } }); }); </script> </body> </html>