How to add data to CKEditor using JQuery

Elitmiar picture Elitmiar · Jan 21, 2010 · Viewed 72.7k times · Source

Everytime a page loads I need to load text into the CK Editor using JQuery, in order to get data from CK Editor I use

var editor_data = CKEDITOR.instances['editor1'].getData();

now is there a similar function I could use to put the data back into the editor?

I'm using ajax to set the data like this

$.ajax({
  type: "POST",
  url: "/inc/ajax/basic.php?menu_id="+menu_id+"&info=3",
  success: function(msg){

    CKEDITOR.instances['editor1'].setData(msg);
  }
});

What am I doing wrong

Answer

PanJanek picture PanJanek · Jan 22, 2010

Try this:

CKEDITOR.instances['editor1'].setData(html)

Where 'html' is a string containing content to edit.