jquery html5上传图片的方法
<div class="upload" > <form><input type="file" id="xFile" style="position:absolute;clip:rect(0 0 0 0);"></form> <label for="xFile" id="car_upload"> <img src="__PUBLIC__/self/images/upload.png" ><br><br>点击上传</label>
</div>
$(function() { $("#xFile").change(function() { // img_data = $("#xFile").get(0).files[0]; var fd = new FormData(); fd.append("upload", 1); fd.append("Filedata", $("#xFile").get(0).files[0]); $.ajax({ url: '/Home/Upload', //server script to process data type: 'POST', data: fd, processData: false, contentType: false, beforeSend: function (XMLHttpRequest) { $("#loading1").show(); }, success: function (r) { // console.log(r); if (r.ret == 0) { $("#idcard_url").val(r.savepath); $("#idcard_urls").attr("src", r.savepath); } else { alert('上传失败'); } $("#loading1").hide(); }, }); });
转载请注明:谷谷点程序 » jquery html5 php上传图片的方法