微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

TinyMCE 5.7 失败回调无论如何都会返回“[object Object]”

如何解决TinyMCE 5.7 失败回调无论如何都会返回“[object Object]”

这里似乎有一个奇怪的问题:我已经使用配置了 per the docsimages_upload_handler 函数启动并运行了 TinyMCE 5.7。如果上传成功,则一切正常。但是,如果上传失败,则应该输出失败消息的对话框只会输出“[object Object]”。

Screenshot: Failure callback output

我发现这就是我在 images_upload_handler 函数调用失败回调的情况,就像文档指示的那样...

function gg_image_upload_handler (blobInfo,success,failure,progress) {
    [...]
    
    if (xhr.status < 200 || xhr.status >= 300) {
      failure('HTTP Error: ' + xhr.status);
      return;
    }

    [...]
}

...或者,如果我使用一个简单的字符串将整个 images_upload_handler 函数设为失败回调,并从中取出所有其他变量(包括 PHP 上传处理程序):

function gg_image_upload_handler (blobInfo,progress) {
    failure('hello!');
    return;
}

值得注意的是,如果我将第二个示例从 "failure('hello!');"到“成功('你好!');”那么就没有问题了:在这种情况下,当我上传照片时,“您好!”出现在通常会出现上传图片路径的对话框中。

我找不到其他遇到失败回调问题的人,所以我担心我做了一些愚蠢的事情,但是其他一切都有效而这部分无效似乎很奇怪。有什么想法吗?完整的 Javascript 代码如下:

function gg_image_upload_handler (blobInfo,progress) {
  var xhr,formData;

  xhr = new XMLHttpRequest();
  xhr.withCredentials = false;
  xhr.open('POST','handlers/tinymce_photo_handler.PHP');

  xhr.upload.onprogress = function (e) {
    progress(e.loaded / e.total * 100);
  };

  xhr.onload = function() {
    var json;

    if (xhr.status === 403) {
      failure('HTTP Error: ' + xhr.status,{ remove: true });
      return;
    }

    if (xhr.status < 200 || xhr.status >= 300) {
      failure('HTTP Error: ' + xhr.status);
      return;
    }
    
    json = JSON.parse(xhr.responseText);

    if (!json || typeof json.location != 'string') {
      failure('Invalid JSON: ' + xhr.responseText);
      return;
    }

    success(json.location);
  };

  xhr.onerror = function () {
    failure('Image upload Failed due to a XHR Transport error. Code: ' + xhr.status);
  };

  formData = new FormData();
  formData.append('file',blobInfo.blob(),blobInfo.filename());

  xhr.send(formData);
};

tinymce.init({
    selector: "textarea#editor",images_upload_handler: gg_image_upload_handler,images_reuse_filename: true,skin: "oxide",plugins: "lists,link,image,media,image code",relative_urls: false,remove_script_host: false,toolbar:
    "h1 h2 h3 h4 h5 h6 bold italic strikethrough blockquote bullist numlist backcolor | link image media | removeformat help",image_caption: true,image_advtab: true,image_class_list: [
        {title: 'Responsive',value: 'img-fluid'}
    ],content_style: 'img { max-width: 75%; height: auto; }',menubar: false,setup: (editor) => {
        // Apply the focus effect
        editor.on("init",() => {
          editor.getContainer().style.transition =
            "border-color 0.15s ease-in-out,Box-shadow 0.15s ease-in-out";
        });
        editor.on("focus",() => {
          (editor.getContainer().style.BoxShadow =
            "0 0 0 .2rem rgba(0,123,255,.25)"),(editor.getContainer().style.borderColor = "#80bdff");
        });
        editor.on("blur",() => {
          (editor.getContainer().style.BoxShadow = ""),(editor.getContainer().style.borderColor = "");
        });
    }
});

解决方法

不幸的是,这是 TinyMCE 5.7.0 中引入的错误,如此处报告的:https://github.com/tinymce/tinymce/issues/6579。这将在即将发布的 TinyMCE 5.7.1 补丁版本中修复,但目前最好的解决方法是降级到 TinyMCE 5.6.2 抱歉。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?