当前位置:网站首页>百度富文本编辑器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())
修改后的文件:
记得这两个文件要同时替换。
边栏推荐
- Food safety - do you really understand the ubiquitous frozen food?
- Equivalent change of resistance circuit (Ⅱ)
- MySQL metadata lock (MDL)
- High score technical document sharing of ink Sky Wheel - Database Security (48 in total)
- 哪个led显示屏厂家更好
- Win11自带画图软件怎么显示标尺?
- 食品安全丨无处不在的冷冻食品,你真的了解吗?
- Endnote add Chinese gbt7714 style how to quote documents in word
- 解决Win10磁盘占用100%
- 使用 Terraform 在 AWS 上快速部署 MQTT 集群
猜你喜欢

Product dynamics - Android 13 high-efficiency adaptation new upgrade

Understanding service governance in distributed development

测试驱动开发(TDD)在线练功房 | 9月17日开课

食品安全丨无处不在的冷冻食品,你真的了解吗?

Ice 100g network card fragment message hash problem

使用 Terraform 在 AWS 上快速部署 MQTT 集群

I interviewed 8 companies and got 5 offers in a week. Share my experience
![Leetcode:154. find the minimum value II in the rotation sort array [about the middle and rear positioning dichotomy of the rotation sort array]](/img/03/54a2d82a17cd07374dc0aedacd7b11.png)
Leetcode:154. find the minimum value II in the rotation sort array [about the middle and rear positioning dichotomy of the rotation sort array]

Crazy God redis notes 12
![[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training](/img/d4/bcc577f320a893c7006177993b2e7a.png)
[IJCAI 2022] parameter efficient large model sparse training method, which greatly reduces the resources required for sparse training
随机推荐
doGet与doPost
面试突击:为什么 TCP 需要 3 次握手?
Record Locks(记录锁)
leetcode:6127. 优质数对的数目【位运算找规律 + 两数之和大于等于k + 二分】
Product upgrade observation station in June
General test case writing specification
MySQL tutorial 67- filter duplicate data using distinct
Endnote cannot edit range resolution
Upgrade esxi6.7.0 to 7.0u3f (updated on July 12, 2022)
Pagehelper.startpage is not effective
优必选大型仿人服务机器人Walker X的核心技术突破
Shared lock
Typescript learning 1 - data types
狂神redis笔记12
阿唐的小帮手
Leetcode:6127. Number of high-quality number pairs [bit operation finding rules + the sum of two numbers is greater than or equal to K + dichotomy]
MySQL table read lock
JWT diagram
Implementation of recommendation system collaborative filtering in spark
Recommended collection, which is probably the most comprehensive coding method summary of category type features