JQuery uploads files, jquery uploads file plug-ins
1. Introduce Resources
<script src="/yami/backend/backres/js/jquery.min.js"></script>
<script src="/yami/backend/backres/js/jquery.ui.widget.js"></script><script src="/yami/backend/backres/js/jquery.iframe-transport.js"></script><script src="/yami/backend/backres/js/jquery.fileupload.js"></script>
2. Add in form<input type="file" name="excel" id="fileupload" style="display:none" onclick="upload()" multiple/>
<AHref =''Onclick ="Document. GetElementById ('Fileupload'). Click ();Return false;"> <DivClass ="Batch"> Batch import user mobile phone numbers </Div> </A>
Click the tag to trigger the <input> Click Event// Select a file and automatically upload the function upload () {$ ('# fileupload '). fileupload ({url: "/yami/backend/coupon. getPhonesFromExcel. do ", dataType: 'json', add: function (e, data) {var goUpload = true; var uploadFile = data. files [0]; if (! (// \. (Xls | xlsx) $/I). test (uploadFile. name) {alert ('select an excel file! '); GoUpload = false;} if (uploadFile. size> 2000000) {// 2 mb alert ('size of the uploaded file cannot exceed 2 mb '); goUpload = false;} if (goUpload = true) {data. submit () ;}, done: function (e, data) {document. getElementById ("showPhones "). innerHTML = "<p> uploaded successfully" + data. result. length + "mobile phone number !!! </P> "; document. getElementById (" phoneList "). setAttribute (" value ", data. result );}});}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.