图片上传服务器显示不全,wangEditor3上传图片到服务器成功,但编辑器不能显示要怎么做?...

var E = window.wangEditor;

var editor = new E('#editor');

// 获取隐藏控件的id,用于显示内容,也方便后台获取内容

var $text1 = $('#content');

// // 监控wangEditor中的内容变化,并将html内容同步更新到 textarea

editor.customConfig.onchange = function (html) {

$text1.val(html);

}

// $base64_image_content=editor.customConfig.uploadImgShowBase64 = true // 使用 base64 保存图片

editor.customConfig.uploadImgServer = 'upload.php'

editor.customConfig.uploadFileName = 'file';

// 将图片大小限制为 3M

editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024 //默认为5M

editor.customConfig.uploadImgShowBase64 = false; // 使用 base64 保存图片

// editor.customConfig.customAlert = function (info) { //自己设置alert错误信息

// // info 是需要提示的内容

// alert(‘自定义提示:‘ + ‘图片上传失败,请重新上传‘)

// };

editor.customConfig.debug = true; //是否开启Debug 默认为false 建议开启 可以看到错误

// editor.customConfig.debug = location.href.indexOf(‘wangeditor_debug_mode=1‘) > 0; // 同上 二选一

//图片在编辑器中回显

editor.customConfig.uploadImgHooks = {

error: function (xhr, editor) {

alert("2:" + xhr + "请查看你的json格式是否正确,图片并没有上传");

// 图片上传出错时触发 如果是这块报错 就说明文件没有上传上去,直接看自己的json信息。是否正确

// xhr 是 XMLHttpRequst 对象,editor 是编辑器对象

},

fail: function (xhr, editor, result) {

// 如果在这出现的错误 就说明图片上传成功了 但是没有回显在编辑器中,我在这做的是在原有的json 中添加了

// 一个url的key(参数)这个参数在 customInsert也用到

//

alert("1:" + xhr + "请查看你的json格式是否正确,图片上传了,但是并没有回显");

},

success:function(xhr, editor, result){

//成功 不需要alert 当然你可以使用console.log 查看自己的成功json情况

//console.log(result)

// insertImg(‘https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png‘)

},

customInsert: function (insertImg, result, editor) {

//console.log(result);

// 图片上传并返回结果,自定义插入图片的事件(而不是编辑器自动插入图片!!!)

// insertImg 是插入图片的函数,editor 是编辑器对象,result 是服务器端返回的结果

// 举例:假如上传图片成功后,服务器端返回的是 {url:‘....‘} 这种格式,即可这样插入图片:

insertImg(result.url);

}

}

editor.create()

// 初始化 textarea 的值

$text1.val(editor.txt.html())

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值