原生jq实现图片上传到服务器

来源:互联网 发布:成交量指标公式源码 编辑:程序博客网 时间:2024/05/18 00:07


//示例代码如下所示

//监听图片上传 icon$(document).on('change','#showIconImgDiv',function (e) {    var targetElement = e.target,file = targetElement.files[0];    var fd = new FormData();    fd.append('fileToUpload',file);    $.ajax({        url : ht.ip.jiaxie + '/uploadaction/addPic',          type : 'post',        data : fd,        contentType : false,        processData : false,        cache : false,        success : function (url) {            uploadUrl.url = ht.ip.jiaxieimg + url;            console.log(uploadUrl.url);            $('.showIconImgLabel').css('background','url('+uploadUrl.url +') center center/cover no-repeat');        }    });});
//url是上传成功返回的  图片在服务器中的地址

原创粉丝点击