更新时间:2017/12/22 下午5:12:09
更新说明:修改错误,之前把form标签id和enctype写到div上了
引入css
<link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/bootstrap-fileinput.css" rel="stylesheet">
引入js
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script> <script src="js/bootstrap-fileinput.js"></script> <script type="text/javascript"> $(function() { //比较简洁,细节可自行完善 $('#uploadSubmit').click(function() { var data = new FormData($('#uploadForm')[0]); $.ajax({ url: 'xxx/xxx', type: 'POST', data: data, async: false, cache: false, contentType: false, processData: false, success: function(data) { console.log(data); if (data.status) { console.log('upload success'); } else { console.log(data.message); } }, error: function(data) { console.log(data.status); } }); }); }) </script>
BUG:当只上传1张图片时,提示至少上传两张,实际上已经设置了minFileCount: 1, //最小文件个数
修复:fileinput.js第1994行,
data = new FileInput(this, $.extend({}, $.fn.fileinput.defaults, options, $(this).data()));
改为
data = new FileInput(this, $.extend({}, $.fn.fileinput.defaults, $(this).data(), options));回复