Error trying to empty CKeditor content

0

I have the following situation, I am placing in my project the CKeditor 4.10 the basic package. No problem is shown to me and I can write and capture the data from him. What happens to me is that when I want to delete the data that is written inside the editor, I am not deleting it and it sends me an error with setData . Then I leave the code and the error to see if you can help me.

Error:

  

Uncaught TypeError: Can not read property 'setData' of undefined

Start instance and delete data feature

HTML

<textarea  name="editor1" id="comentario" rows="5" placeholder="Comentario" class="form-control border-input"></textarea>

JavaScript

 if($("textarea#comentario").length > 0){
        CKEDITOR.replace( 'editor1' );

        function CKupdate(){
            CKEDITOR.instances.editor1.setData('');
        }
    }

Data capture and call to editor data cleanup

var guardarcomentario = function(){

    $("#fidcoment").submit(function(e){

        if($("textarea#comentario").val() != ''){
            e.preventDefault();
            var dataString = new FormData($(this)[0]);
              $.ajax({
                    type: "POST",
                    url: "index.php?c=pendientes&f=comentario",
                    data: dataString,
                    cache: false,
                    contentType: false,
                    processData: false,
                    //mientras enviamos el archivo
                    beforeSend: function(){
                        message = $("<div class='alert alert-error'><span class='before'>Subiendo, por favor espere...</span></div>");
                        $("div#iderrorc").html(message);      
                    },                                
                    success: function (datos) {
                        CKupdate();
                        $("div#iderrorc").html(datos);
                        $("input#idEnviar").prop('disabled', true);
                    },
                    //si ha ocurrido un error
                    error: function(){
                        message = $('<div class="alert alert-error">Ha ocurrido un error.</span>');
                        $("div#iderrorc").html(message);
                    }  
                }).done(function(info){
                       console.log( info ); 
                });            
        }

       return false; 
    });

} 

Thank you.

    
asked by Yoel Rodriguez 12.07.2018 в 21:24
source

1 answer

1

Empty the textarea.

$("#comentario").val("");

I hope it serves you.

    
answered by 12.07.2018 в 22:19