zoukankan      html  css  js  c++  java
  • kindeditor编辑器上传图片跨域

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

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

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

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

    //uploadbutton.submit();

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

    var formData = new FormData();
    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 = '<img src="' + self.options.basePath + data.url + '" />';
            //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:本文是为了遇到类似问题时方便本人查找

    原文链接:https://blog.csdn.net/alongxiao/java/article/details/104831596

  • 相关阅读:
    es 报错cannot allocate because allocation is not permitted to any of the nodes
    linux下获取软件源码包 centos/redhat, debian/ubuntu
    windows假死原因调查
    k8s-calico
    helm使用
    docker网络模式
    4、formula 法则、原则、数学公式
    powershell自动添加静态IP
    WDS部署Windows server2012初试
    2、puppet资源详解
  • 原文地址:https://www.cnblogs.com/97pkp/p/12894727.html
Copyright © 2011-2022 走看看