How to add data to CKEditor using JQuery

让人想犯罪 __ 提交于 2019-11-28 04:31:26

Try this:

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

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

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

CKEDITOR.instances.editor1.setData(html)
Vaibhav Jain

you should use data, and method for sending query string like this:

$(document).ready(function()
{
  var querystring="menu_id="+menu_id+"&info=3";
  $.ajax({
  method: "POST",
  url: "/inc/ajax/basic.php",
  data:querystring,
  success: function(msg)
   {
     CKEDITOR.instances['editor1'].setData(msg);
   }
  });
});
var jqxhr = $.get( "file.php", function(data) {
CKEDITOR.instances.idOftextAreaName.setData( data );
    alert( "success" );
  })
.done(function() {
    //alert( "second success" );
})
.fail(function() {
    alert( "error" );
})
.always(function() {
   // alert( "finished" );
});
var editor = CKEDITOR.instances.help_ldesc;         
editor.setData(''); 
$.ajax({
url: urlstr, // Url to which the request is send
type: "POST",             // Type of request to be send, called as method
data:{action:"ex_form"}, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false,       // The content type used when sending data to the server.
cache:false,             // To unable request pages to be cached
processData:false,        // To send DOMDocument or non processed data file it is set to false
success: function(data)   // A function to be called if request succeeds
{
    //alert(data);
    var data1=data.split("~`");
    $('#help_id').val(data1[0]);
    $('#help_title').val(data1[1]);
    $('#help_sdesc').val(data1[2]);                 

    editor.setData(''+data1[3]);    
    var edata = editor.getData();
    alert(edata);
}
});

Use this code its works for me and (help_ldesc) is my textarea name.

Happy Patel
CKEDITOR.instances['<%=ckEditor.ClientID%>'].setData(value);

From my experience using inside a function sometimes doesn't work properly. I'll suggest to use in:

    $(document).ready(function () {
    ...
    // instance, using default configuration.
    CKEDITOR.replace('editor1');
    //set data
    CKEDITOR.instances['editor1'].setData(data);
    ...
    });
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!