jquery 异步上传
$(".camera").change(function() {
var data = new FormData();
data.append('file', $('.camera')[0].files[0]);
layer.open({ type: 2 });
$.ajax({
url: "{:U('Home/Users/uploadPic')}",
data: data,
contentType: false,
processData: false,
dataType: 'json',
type: 'POST',
success: function(data) {
layer.closeAll();
if (data) {
if (data['status'] == 1) {
var file = data['file'];
img = file['savepath'] + file['savename'];
$("#permImg").val(img);
$("#imgpage").css("background-image","url(" + img + ")");
$("#imgpage").css("background-size","cover");
$("#imgpage").css("background-position","center center");
$("#imgpage").css("background-repeat","no-repeat");
$("#imgpage").show();
showmsg("上传成功");
} else {
layer.closeAll();
if (data['msg']) {
showmsg("发送失败," + data['msg']);
} else {
showmsg("发送失败,请稍后再试");
}
}
}
}
})
})