How to pass data from a search done in ajax / php / mysql to a textarea with ckeditor

0

I'm working on a control panel for the site where the news posts are made.

By it you can edit the news if necessary, I'm using CKEDITOR in my textarea , the query is done with ajax / php , but I can not play searched text in banco for editing back in textarea with CKEDITOR . Can someone give me strength?

function editaTextoNoticia(idd) {
    var url = "buscaEditarTextoNoticia.php?id=" + idd;
    req2.open("Get", url, true);
    req2.onreadystatechange = function() {
        if (req2.readyState == 1) {
            document.getElementById('textoEditar').innerHTML = 'Carregando...';
        }
        if (req2.readyState == 4 && req2.status == 200) {
            var resposta = req2.responseText;
            CKEDITOR.instances.textoEditar.updateElement();
        }
    };
    req2.send(null);
}
    
asked by anonymous 21.01.2016 / 20:19

2 answers

0

The question is vague, with no code, etc. But I've already worked with CKEditor and there's no secret, check the following questions:

1 - Reference the file js of the editor:

<script src="libs/ckeditor/ckeditor.js"></script>

2 - Add class="ckeditor" to textarea you want to use editor:

<textarea class="ckeditor" name="editor"></textarea>

3 - If you use PHP , give echo to write text in the editor:

<textarea class="ckeditor" name="editor"><?php echo $meuTexto; ?></textarea>

4 - If you use Jquery , use:

$(".ckeditor").val("meu texto");
    
21.01.2016 / 20:29
0

On line

  var resposta = req2.responseText; 

You have added what returns from the ajax in the response variable, but did not throw into your field, you have to include it with (in the case of textarea)

 CKEDITOR.instances.idDoTextarea.setData (resposta) 

Where idDoTextArea is the id of your textarea (logical rs)

    
21.01.2016 / 20:38