图片上传及显示

简单明了的图片上传及显示


$(fileId).change(function(){
var objUrl = getURL(this.files[0]);
if(objUrl){
$("img").attr("src",objUrl);
}
})

//获取图片路径
function getURL(file){
var url=null;
if (window.createObjectURL != undefined) {
url = window.createObjectURL(file);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(file);
}
return url;
}

用ajax上传图片
$.ajax({
url: 上传路径 ,
type: 'POST',
data: _formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (data) {
console.log(data);
},
error: function (data) {
console.log(data);
}
});


你可能感兴趣的:(es5)