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

Asked

Viewed 147 times

0

I’m working on a control panel for website where the news posts are made.

For it you can edit the news if necessary, I’m using the CKEDITOR in my textarea, the consultation shall be made by means of ajax/php, but I can’t play the searched text on banco for editing back on textarea with CKEDITOR. Someone can give me a boost?

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);
}
  • 1

    Post part of code with error

  • Click edit the question friend, before reading the tour to learn how to use the site: http://answall.com/tour

2 answers

0

The question is vague, no code, etc. But I have worked with CKEditor and has no secret, check the following questions:

1 - Reference the archive js of the editor:

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

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

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

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

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

4 - If to use Jquery, use:

$(".ckeditor").val("meu texto");
  • Well I will try to explain better. I have a news editing page. These news are registered in a mysql database. I need to edit a news, where the data is searched through an ajax/php search in the database, when returning the result, the text should appear in a textarea that uses ckeditor. I couldn’t find a way to send the text returned from the search to the textarea. In this case, the code snippet I sent you is the ajax snippet that takes the data to be searched and returns the information obtained to the user. I hope it became clearer.

0

On the line

  var resposta = req2.responseText; 

You added what returns from the ajax in the response variable, but did not throw it 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 (logico rs)

  • I’ve tried this, if the textarea is pure it works, but using the Ckeditor it goes blank.

  • That’s how it worked! Thank you!

  • nothing, good development there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.