How to add data to CKEditor using JQuery

后端 未结 7 1965
无人及你
无人及你 2020-12-07 20:33

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[\'         


        
相关标签:
7条回答
  • 2020-12-07 21:12

    Try this:

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

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

    0 讨论(0)
  • 2020-12-07 21:19
    CKEDITOR.instances['<%=ckEditor.ClientID%>'].setData(value);
    
    0 讨论(0)
  • 2020-12-07 21:19

    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);
        ...
        });
    
    0 讨论(0)
  • 2020-12-07 21:21

    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);
       }
      });
    });
    
    0 讨论(0)
  • 2020-12-07 21:27
    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" );
    });
    
    0 讨论(0)
  • 2020-12-07 21:29
    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.

    0 讨论(0)
提交回复
热议问题