ajax 图片上传

来源:互联网 发布:全国ip网络广播系统 编辑:程序博客网 时间:2024/06/06 11:42
话不多说,直接贴代码

$('.ajax-post').click(function(){
varform_data=$('form').serializeArray();
varform=newFormData();
$.each(form_data,function(){
form.append(this.name,this.value);
});
form.append('goods_img',$('.goods_img')[0].files[0]);
$.each($('.goods_photo'),function(){
form.append('goods_photo[]',this.files[0]);
});
$.ajax({
type:'POST',
url:"<?=site_url('Goods/insert')?>",
data:form,
dataType:'json',
cache:false,
contentType:false,
processData:false,
success:function(res){
alert(res.message);
if(res.code==0){
return false;
}
location.href= res.url;
}
});
});
原创粉丝点击