Summernote Show Images that have been uploaded to a folder

两盒软妹~` 提交于 2019-12-01 11:09:00

In the new version of summernote onImageUpload callback is called only with files argument. It means that editor is not available.

You can insert an image with:

$('.summernote').summernote("insertImage", url, filename);

In your case:

$('.summernote').summernote("insertImage", data, 'filename');

I did it using codeigniter may be this help someone.

 $(function() {
          $('.summernote').summernote({
              onImageUpload: function(files, editor, $editable) {
              sendFile(files[0],editor,$editable);
              }  
            });

           function sendFile(file,editor,welEditable) {
              data = new FormData();
              data.append("file", file);
               $.ajax({
               url: "http://localhost/fourm/media/editorupload",
               data: data,
               cache: false,
               contentType: false,
               processData: false,
               type: 'POST',
               success: function(data){  
                editor.insertImage(welEditable, data);              
            },
               error: function(jqXHR, textStatus, errorThrown) {
               console.log(textStatus+" "+errorThrown);
              }
            });
           }
    });

You must use "callbacks: {}" method. like this:

$('.summernote').summernote({
    height: 500,
    tabsize: 4,
    callbacks: {
        onImageUpload: function(files, editor, $editable) {
            console.log('onImageUpload');
            sendFile(files[0],editor,$editable);
        }
    }});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!