36

ページが読み込まれるたびに、使用するCK Editorからデータを取得するために、JQueryを使用してCKEditorにテキストを読み込む必要があります。

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
CKEDITOR.instances['<%=ckEditor.ClientID%>'].setData(value);
于 2013-03-21T10:50:29.247 に答える
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
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 に答える