//图片原件上传功能 function gosubmit(file, key) { var formData = new FormData($("#inputForm")[0]); formData.append('pic', file.files[0]); $.ajax({ url: '***', type: 'post', contentType: false, data: formData, processData: false, dataType: 'json', success: function (data) { $("#licencePicUrl").css('display', 'block'); $("#licencePicUrl").attr("src", data.url); $("#licencePic").val(data.url); }, error: function (err) { alert("请检查网络"); } }); } //图片原件上传功能 end
<a href="javascript:;" class="file"> <input type="file" accept="image/jpg,image/jpeg,image/png" name="file" id="chooseImg" onchange="gosubmit(this,'0')"> 上传图片 </a>
<form id="inputForm" method="post" class="form-horizontal" enctype="multipart/form-data">