ueditor单图上传iframe跨域_UEditor单图上传(simpleupload)跨域问题解决方案
代碼實(shí)現(xiàn)
首先我們需要在ueditor.all.js文件中找到原本的單圖上傳部分的代碼
搜索關(guān)鍵字?simpleupload,如下圖所示:
然后找到上傳圖片的代碼片段,如下圖所示:
然后把?domUtils.on的?input 綁定的事件注釋掉或刪除掉
替換成以下代碼:input.onchange?=?function?()?{
if?(!input.value)?return;
var?loadingId?=?"loading_"?+?(+new?Date()).toString(36);
var?params?=
utils.serializeParam(me.queryCommandValue("serverparam"))?||?"";
var?imageActionUrl?=?me.getActionUrl(me.getOpt("imageActionName"));
var?imageUrlPrefix?=?me.getOpt("imageUrlPrefix");
var?allowFiles?=?me.getOpt("imageAllowFiles");
me.focus();
me.execCommand(
"inserthtml",
????????????????????'
loadingId?+
'"?src="'?+
me.options.themePath?+
me.options.theme?+
'/images/spacer.gif">'
);
/*?判斷后端配置是否沒有加載成功?*/
if?(!me.getOpt("imageActionName"))?{
errorHandler(me.getLang("autoupload.errorLoadConfig"));
return;
}
//?判斷文件格式是否錯誤
var?filename?=?input.value,
fileext?=?filename???filename.substr(filename.lastIndexOf("."))?:?"";
if?(
!fileext?||
(allowFiles?&&
(allowFiles.join("")?+?".").indexOf(fileext.toLowerCase()?+?".")?==
-1)
)?{
showErrorLoader(me.getLang("simpleupload.exceedTypeError"));
return;
}
var?formData?=?new?FormData()
formData.append('upfile',?input.files[0]);
//?替換你的URL
$.ajax(imageActionUrl,?{
data:?formData,
processData:?false,
contentType:?false,
type:?"post",
success:?function?(data)?{
try?{
var?link,
json,
loader;
json?=?JSON.parse(data);
link?=?imageUrlPrefix?+?json.url;?if?(json.state?==?"SUCCESS"?&&?json.url)?{
loader?=?me.document.getElementById(loadingId);
domUtils.removeClasses(loader,?"loadingclass");
loader.setAttribute("src",?link);
loader.setAttribute("_src",?link);
loader.setAttribute("alt",?json.original?||?"");
loader.removeAttribute("id");
me.fireEvent("contentchange");
}?else?{
showErrorLoader?&&?showErrorLoader(json.state);
}
}?catch?(er)?{
showErrorLoader?&&
showErrorLoader(me.getLang("simpleupload.loadError"));
}
}
});
function?showErrorLoader(title)?{
if?(loadingId)?{
var?loader?=?me.document.getElementById(loadingId);
loader?&&?domUtils.remove(loader);
me.fireEvent('showmessage',?{
'id':?loadingId,
'content':?title,
'type':?'error',
'timeout':?4000
});
}
}
}
需要注意的是,本文中的以上代碼已經(jīng)過修改及修復(fù),無需像原文中那樣單獨(dú)指定服務(wù)器路徑(前提是保證后端配置的ueditor.json文件是正確的)
更多詳細(xì)請看原文,感謝原作者的解決方案。
總結(jié)
以上是生活随笔為你收集整理的ueditor单图上传iframe跨域_UEditor单图上传(simpleupload)跨域问题解决方案的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 护眼行业新标杆!荣耀100系列将首发荣耀
- 下一篇: java 双击_利用java开发一个双击