700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > kindeditor php 跨域 kindeditor编辑器上传图片跨域

kindeditor php 跨域 kindeditor编辑器上传图片跨域

时间:2021-06-06 09:47:58

相关推荐

kindeditor php 跨域 kindeditor编辑器上传图片跨域

项目通常引入的是kindeditor-all.min.js,这里我们需要改为引入kindeditor-all.js,因为要对其源码进行修改。

1.打开文件,搜索下面的这行代码:

KindEditor.plugin('image', function(K) {

2.查找下面提交图片办法,并将其注释掉,因为会出现跨域问题:

//uploadbutton.submit();

3.把下边的代码粘在上一行代码的后边:

var formData = newFormData();var file=uploadbutton.fileBox[0].files[0];

formData.append(file.name, file);//console.log(file,formData)

K.ajaxForm(self.options.uploadJson, function(data) {

dialog.hideLoading();//console.log(data);

if (data.error==0) {//console.log(self.options);

var html = '';//console.log(html)

self.appendHtml(html).hideDialog().focus();

}

},'POST',formData,'json');

4.输入_ajax,查找_ajax名称的函数,在此函数的后面新增如下代码:

function_ajaxForm(url, fn, method, param, dataType) {

method= method || 'GET';

dataType= dataType || 'json';var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');

xhr.open(method, url,true);

xhr.onreadystatechange= function() {if (xhr.readyState == 4 && xhr.status == 200) {if(fn) {var data =_trim(xhr.responseText);if (dataType == 'json') {

data=_json(data);

}

fn(data);

}

}

};

xhr.send(param);

}

5.在此函数后面加上如下代码,这样就可以用ajax方式上传图片了:

K.ajaxForm=_ajaxForm;

tip:本文是为了遇到类似问题时方便本人查找

原文链接:/alongxiao/java/article/details/104831596

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。