36

每次加载页面时,我都需要使用 JQuery 将文本加载到 CK 编辑器中,以便从我使用的 CK 编辑器中获取数据

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

现在有没有类似的功能可以用来将数据放回编辑器?

我正在使用ajax来设置这样的数据

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

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

我究竟做错了什么

4

7 回答 7

72

尝试这个:

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

其中 'html' 是包含要编辑的内容的字符串。

于 2010-01-22T14:26:25.113 回答
11

因为它不是数组,所以只需像这样替换实例

CKEDITOR.instances.editor1.setData(html)
于 2012-11-04T11:45:32.627 回答
2
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);
}
});

使用此代码对我有用,并且 (help_ldesc) 是我的文本区域名称。

于 2016-03-03T05:44:48.027 回答
1

您应该使用数据和发送查询字符串的方法,如下所示:

$(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);
   }
  });
});
于 2013-09-13T09:35:32.590 回答
1
CKEDITOR.instances['<%=ckEditor.ClientID%>'].setData(value);
于 2013-03-21T10:50:29.247 回答
1
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" );
});
于 2014-03-05T19:30:31.040 回答
0

根据我在函数内部使用的经验,有时无法正常工作。我会建议使用:

    $(document).ready(function () {
    ...
    // instance, using default configuration.
    CKEDITOR.replace('editor1');
    //set data
    CKEDITOR.instances['editor1'].setData(data);
    ...
    });
于 2016-03-04T10:06:48.323 回答