当前位置:网站首页>百度富文本编辑器UEditor单张图片上传跨域
百度富文本编辑器UEditor单张图片上传跨域
2022-07-25 16:10:00 【苦夏木禾】
官方文档说明:
修改如下:
采用Ajax上传的方式来解决这个问题
首先我们需要修改ueditor.all.js,这里参考doAjax,新增doAjaxFile函数用来上传文件:
function doAjaxFile(url, ajaxOptions) {
console.log('doAjaxFile-----------------------------------------------------------')
console.log(url)
console.log(ajaxOptions)
var xhr = creatAjaxRequest(),
//是否超时
timeIsOut = false,
//默认参数
defaultAjaxOptions = {
method: 'POST',
//超时时间。 默认为5000, 单位是ms
timeout: 15000,
//是否是异步请求。 true为异步请求, false为同步请求
async: true,
//请求携带的数据。
data: {
},
processData: false,
contentType: false,
cache: false,
onsuccess:function() {
},
onerror:function() {
}
};
if (typeof url === "object") {
ajaxOptions = url;
url = ajaxOptions.url;
}
if (!xhr || !url) return;
var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
//超时检测
var timerID = setTimeout(function() {
if (xhr.readyState != 4) {
timeIsOut = true;
xhr.abort();
clearTimeout(timerID);
}
}, ajaxOpts.timeout);
var method = ajaxOpts.method.toUpperCase();
var str = url + (url.indexOf("?")==-1?"?":"&")
xhr.open(method, str, ajaxOpts.async);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (!timeIsOut && xhr.status == 200) {
ajaxOpts.onsuccess(xhr);
} else {
ajaxOpts.onerror(xhr);
}
}
};
// xhr.upload.addEventListener("progress", function(event) {
// if(event.lengthComputable){
// progress.style.width = Math.ceil(event.loaded * 100 / event.total) + "%";
// }
// }, false);
xhr.send(ajaxOpts.data);
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
然后在UE.Ajax中新增函数:
sendfile:function(url, opts) {
doAjaxFile(url, opts);
}
最后就是替换下面函数的代码:
domUtils.on(input, 'change', function())
修改后的文件:
记得这两个文件要同时替换。
边栏推荐
猜你喜欢
随机推荐
Use huggingface to quickly load pre training models and datasets in moment pool cloud
Equivalent change of resistance circuit (Ⅱ)
R语言偏相关性计算(Partial Correlation)、使用ggm包的pcor函数计算偏相关性(Partial Correlations)
Release of v6.5.1/2/3 series of versions of Xingyun housekeeper: the ability of database OpenAPI continues to be strengthened
Endnote cannot edit range resolution
MySQL教程67-使用DISTINCT过滤重复数据
Golang review summary
记得那两句话
面试突击:为什么 TCP 需要 3 次握手?
排他锁(EXclusive Lock)
ML - Speech - Introduction to speech processing
C# 模拟抽奖
Exclusive lock
MySQL self incrementing lock
可验证随机函数 VRF
[wechat applet] detailed explanation of applet host environment
Implementation of recommendation system collaborative filtering in spark
Shared lock
【故障诊断】基于贝叶斯优化支持向量机的轴承故障诊断附matlab代码
面试8家公司,1周拿了5个offer,分享一下自己的心得






![[wechat applet] detailed explanation of applet host environment](/img/57/582c07f6e6443f9f139fb1af225ea4.png)


