wanka
$("#file input[type=file]").on("change", function(event){
var files = event.target.files;
var data = new FormData();
$.each(files, function(key, value)
{
data.append("file", value);
});
$.ajax({
url: "",
type: "POST",
data: data,
async: true,
cache: false,
dataType: "json",
processData: false,
contentType: false,
success: function(){
if(data.error_code === 0){
$('#icon').removeClass('hidden');
$('#icon input').val(data.url);
$('#icon img').attr('src', data.url);
$("#file").addClass("hidden");
$("#file input[type=file]").val("");
}else{
$("#file input[type=file]").val("");
var errorMsg = data.error_msg || "图片上传失败,请重试!";
alert(errorMsg);
}
},
error: function(data,jqXHR, textStatus, errorThrown){
alert(JSON.parse(data.responseText).error_msg);
}
});
});