Search code examples
jqueryckeditortextarea

How to get content from CK Editor?


I need to get content from CK Editor to put it in JQuery.

	
				<form action="php/showcomments.php" method="post" onsubmit="return false;" >
				<div class="text-cmt">
					<input id="tittle" name="tittle" type="text" placeholder="Comment Title" id="comm" required/>
				</div>
				<div class="text-cmt">
					<textarea id="msg"  ></textarea>
	
				</div>
				<div class="text-cmt">
					<input name="send"  type="submit" value="send">
				</div>
				</form>
					<script>
        CKEDITOR.replace( 'msg' );
    </script>

<script>
$(document).ready(function(){
	var g_id = "<?= $id; ?>";
	var u_id = "<?= userid; ?>";
	
  //  var comm = tinyMCE.editor.getContent();
	//tinyMCE.get('editor').getContent()
	  $("form").submit(function(){
		  var comm =  $("#tittle").val();
   	 $.ajax({
      url: 'php/showcomments.php', // form action url
      type: 'POST', // form submit method get/post
      data: {tittle: $("#tittle").val(),comm: comm, g_id: g_id,  u_id: u_id },
      dataType: 'html',
	  success: function(data)
	  {
		  alert(data);
      },
	 });
    });
});
</script>


Solution

  • You can get content of ck editor using

    JS for CKEditor 3.6.x

    var editor = CKEDITOR.editor.replace('msg');
    
    $('#send').click(function() {
        var value = editor.getData();
        // send your ajax request with value
        // profit!
    });
    

    JS for CKEditor 4.0.x

    $('#send').click(function() {
        var value = CKEDITOR.instances['DOM-ID-HERE'].getData()
        // send your ajax request with value
        // profit!
    });