//上传图片,获取url
$("#file").change(function (){
if (!$(this).val()){return}
var fileData = new FormData();
fileData.append("file", $('#file')[0].files[0]);
console.log($('#file')[0].files[0])
$.ajax({
url:IMG_UPLOAD_URL,
type: "POST",
contentType: false,//核心,如果为true的时候,jq就会去操作这个分界符,导致后台服务器无法操作数据,导致请求失败。
processData: false,//核心,默认为true,规定通过请求发送的数据是否转换为查询字符串,
data:fileData,
success(res){
//图片预览
$("#titleImg").attr("src",JSON.parse(res.data).img_url);
}
})
})
使用jquery上传图片文件(便于理解,省略了图片校验)
猜你喜欢
转载自blog.csdn.net/weixin_43158695/article/details/112844955
今日推荐
周排行