标签:log type span method json you put size app
<body> <input type="file" id="myFile" onchange="beforeUpload()"> <button onclick="selectFile()">上传</button> <script> var fileInput = document.getElementById("myFile"); // 选择上传文件 function selectFile(event){ fileInput.click(); } // 上传之前操作 function beforeUpload(event){ /* * 上传前的校验 例如 * 1.文件大小不能超过5M **/ var file = fileInput.files[0]; var isGT5M = file.size / 1024 /1024 >50; if(isGT5M){ alert("对不起您上传的文件大于50M 不润许上传"); } var form = new FormData(); form.append(‘file‘, file); // ajax上传请求 uploadFile(form) } function uploadFile(data){ fetch(‘http://callyou.iopooo.com/api/common/upload‘,{ method:‘POST‘, body:data }) .then(function(response) { return response.json(); }) .then(function(myJson) { console.log(myJson); }); } </script> </body>
标签:log type span method json you put size app
原文地址:https://www.cnblogs.com/liangfc/p/12230925.html