js上传excel

2018-06-12  本文已影响0人  VIAE
 <input type="file" id="fileInput" name="fileInput"  onChange={()=>formdate("fileInput")} accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"/>   
      
function formdate(id){
        document.getElementById(id).addEventListener('change', uploadFile, false);
        function uploadFile(e){
            console.log(e.target.files[0]);
            var file = e.target.files[0];
            var formData = new FormData(id,file);
            formData.append('name',attribute)            
            var xhr = new XMLHttpRequest();
            xhr.open('POST', 'url', true);
            xhr.send(formData);
        }
上一篇下一篇

猜你喜欢

热点阅读