`

ajax上传图片

阅读更多
$('.file').change(function(){
                var formData = new FormData();
                for(x in $(this)[0].files){
                    formData.append("file", $(this)[0].files[x]);
                }
                $.ajax({
                    url : "/upload/uploadFile.do",
                    type : "post",
                    cache: false,
                    data: formData,
                    dataType:"json",
                    processData: false,
                    contentType: false,
                    success: function(result){
                        if(result.code == "1" && result.data){
                            //bootbox.alert("文件上传成功!");
                            $('.uploadImageSuccess').show().attr('src',imgPath+'/'+result.data[0])
                            $('[name=infoImgUrl]').val(result.data[0]);
                        } else {
                            bootbox.alert(result.msg);
                        }
                    }});

            });

});

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics