var editor = ""; //初始化编辑器 function initEditor() { var E = window.wangEditor; editor = new E('#editorMessage'); editor.customConfig.uploadImgServer = '/rest/message/uploadFile'// 配置服务器端接口地址 editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;//图片大小限制3M editor.customConfig.uploadImgMaxLength = 1;//限制每次上传为1张 editor.customConfig.customUploadImg = function (files, insert) {//对上传的图片进行处理,图片上传的方式 var formData = new FormData() formData.append("file", files[0]) var index = undefined; $.ajax({ type: 'post', url: "/rest/message/uploadFile", data: formData, cache: false, processData: false, contentType: false, beforeSend: function () { index = layerLoadingMsg("正在上传...") }, success: function (data) { layerClose(index); if (data.retCode == "0") { layerSuccessTips("上传成功"); var url = data.object.fileUrl;//获取上传图片路径 insert(url);//插入编辑框 }else{ layerErrorTips("上传文件失败") } }, error: function (data) { layerClose(index); layerErrorTips("上传文件失败") } }) } editor.create(); }