Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add data to CKEditor using JQuery

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

like image 324
Elitmiar Avatar asked Jan 21 '10 10:01

Elitmiar


People also ask

How do I load content in CKEditor?

CKEditor automatically sets the content of the new textarea using what is originally within the old, replaced one. In other words, it's sufficient to change the content of the textarea and only then call the replace command. This would be the code: document.

Does CKEditor use jQuery?

Thanks to these changes CKEditor 4 automatically works with the official jQuery Form Plugin for Ajax-based forms. It does not require any action from the developer's side to support it.

How do I set a value in CKEditor with JavaScript?

[form name]. [textarea name]. value=data; $('#textareaID'). val(data);


2 Answers

Try this:

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

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

like image 168
PanJanek Avatar answered Oct 11 '22 03:10

PanJanek


Because its not an array then just replace the instance like this

CKEDITOR.instances.editor1.setData(html) 
like image 20
mac786751 Avatar answered Oct 11 '22 04:10

mac786751