2017-10-31 1 views
0

TinyMCE를 WYSIWYG 편집기로 사용하려고합니다. 내 서버에 이미지를 업로드 할 때, 나는 내용의 오류 :TinyMCE uploadImages() 함수가 작동하지 않습니다.

재산 'uploadImages'정의되지 않은

나는 정확한 문서를 읽는 오전,하지만 일부를 읽을 수 없습니다 이유는 기능을 인식하지 못하기 때문입니다. 여기에 내 코드입니다 :

<!DOCTYPE html> 
<html> 

<head> 
    <link href="resources/css/index.css" rel="stylesheet" type="text/css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script> 
</head> 

<body> 
    <div id="container"> 
     <form> 
      <label>Title</label> 
      <input type="text" name="title"> 

      <label>Description</label> 
      <input type="text" name="desct"> 

      <textarea id="editor"></textarea> 

      <input type="submit"> 
     </form> 
    </div> 
</body> 
<script> 
    tinymce.init({ 
     selector: '#editor', 
     theme: 'modern', 
     browser_spellcheck: true, 
     height: 480, 
     images_upload_url: 'resources/scripts/postAcceptor.php', 
     images_upload_base_path: '/tutorials/resources/images/', 
     images_upload_handler: function (blobInfo, success, failure) { 
      this.activeEditor.uploadImages(function(success) { 
       $.post('resources/scripts/postAcceptor.php', this.activeEditor.getContent()).done(function() { 
       console.log("Uploaded images and posted content as an ajax request."); 
       }); 
      }); 
     }, 
     plugins: [ 
      'advlist autolink link code image lists charmap print preview hr anchor pagebreak spellchecker', 
      'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking', 
      'save table contextmenu directionality emoticons template paste textcolor' 
     ], 

     toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons | fontselect' 
    }); 

</script> 

</html> 

답변

0

오류가 images_upload_handler 키에있는 함수 내에서 코드가 this.activeEditor를 얻기 위해 시도하는이지만,이 변수는이 문서 https://www.tinymce.com/docs/api/tinymce/tinymce.editor/을 바탕으로 undefined

images_upload_handler: function (blobInfo, success, failure) { 
    this.activeEditor.uploadImages(function(success) { 
     $.post('resources/scripts/postAcceptor.php', this.activeEditor.getContent()).done(function() { 
      console.log("Uploaded images and posted content as an ajax request."); 
     }); 
    }); 
}, 

을 반환 예 : tinymce.activeEditor이어야합니다.

추신 : 당신은 무엇을 하려는지 조용히하지 마십시오. 만약 내가 올바르게 이해한다면, post 메소드를 실행해서는 안되며, 스스로 수행해야합니다. 포스트가 성공적으로 완료되거나 실패한 후에 실행되는 함수 만 보내야합니다. 해당 게시물 메서드를 해당 처리기 내에 배치하면 아마도 두 번 업로드됩니다. 전체 기능 데모보기 : https://www.tinymce.com/docs/demo/full-featured/

+0

이렇게하려고합니다 : https://www.tinymce.com/docs/get-started/upload-images/ uploadImages() 함수가 작동하지 않습니다. 조금도. 나는 사용자가 업로드 한 이미지를 서버에 보내려하고있다. – user2896120

+0

@ user2896120 오, 알 겠지만, 예제에서는 JSON 구성을 통해 확인하지 못했지만 모든 것이 바깥에있는 것처럼 보입니다. 그는'tinymce.activeEditor.uploadImages' 메소드에 함수를 보낸다. – Frankusky

관련 문제