ajax上传图片
代码:
form.on('submit(suu)', function(data){
layedit.sync(suun);
var formData = new FormData(data.form);
var oFiles = $("#filess").get(0).files;
console.log(oFiles);
// 遍历图片文件列表,插入到表单数据中
for (var i = 0, file; file = oFiles[i]; i++) {
// 文件名称,文件对象
formData.append('files['+i+']', file);
}
$.ajax({
type: 'post',
url: "{:url('Welfare/project')}",
data : formData,
processData : false,
contentType: false,
success: function(res){
if (res.isSuccess) {
layer.msg(res.msg,{shade:'#fefefe',icon:1,time:2000},function(){
window.parent.location.reload();
});
}else{
layer.msg(res.msg, {shade:'#fefefe',icon: 2, time: 2000});
}
}
}) ;