javascript – tinymce使用文件浏览器添加图像[暂停]

我在我的网络博客上有一个添加帖子功能的以下代码,我有一个允许文件选择的按钮,但它不起作用.有帮助吗?

      tinymce.init({

          selector: "textarea",
          plugins: [
              "advlist autolink lists link image charmap print preview anchor",
              "searchreplace visualblocks code fullscreen",
              "insertdatetime media table contextmenu paste"
          ],
          toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",

          file_browser_callback : 'myFileBrowser'


      });

解决方法:

我希望它能帮到你

 tinymce.init({
      selector: 'textarea',  // change this value according to your HTML
      images_upload_handler: function (blobInfo, success, failure) {
        var xhr, formData;

        xhr = new XMLHttpRequest();
        xhr.withCredentials = false;
        xhr.open('POST', 'postAcceptor.php');

        xhr.onload = function() {
          var json;

          if (xhr.status != 200) {
            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);
        };

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

        xhr.send(formData);
      }
    });

更多细节

https://www.tiny.cloud/docs/configure/file-image-upload/

上一篇:php – 如何在wordpress MCE编辑器中添加自定义选项和按钮


下一篇:javascript – 使用tinyMCE剥离的HTML标签