---------------------formData上傳圖片---------------------ajax
<form id="imageform">
<img src="img/user_logo_center.png" class="user_logo"/>
<i class="change_pho"></i>
<input type="file" name="photo" accept="image/png,image/gif,image/jpg,image/jpeg" id="change_pho_btn">
<form>app
$("#change_pho_btn").on("change",function(){
var formData = new FormData($( "#imageform" )[0]);async
formData.append("type", "avatar");url
$.ajax({
url: '',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (data) {
$('#imageform .user_logo').attr('src',data.img_url);
},
error:function(){
}
});
})orm
----------------------獲取客戶端圖片連接--------------------------------對象
---》必須爲文件對象或者BLOB對象(2進制對象)圖片
var img_url=window.URL.createObjectURL($("#upload_pic").get(0).files[0])get
$("img").attr("src",img_url)input