tineMCE 踩坑:images_upload_handler

tineMCE 的官方示例提供了前端上传图片方法 images_upload_handler 的写法。

但官方写的有点问题,上传会报错。

不过修改也很简单:

images_upload_handler: function (blobInfo, success, failure) {
    var xhr, formData;

    xhr = new XMLHttpRequest();
    xhr.withCredentials = false;
    xhr.open('POST', 'http://localhost/oasis_publish_test_php/index.php/upload/upImg');

    xhr.onload = function() {
      var json;

      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);
    };

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

    xhr.send(formData);
  }

标红的部分就是修改的部分。

posted on 2018-09-26 22:56  fox_charon  阅读(6308)  评论(0编辑  收藏  举报

导航