CKEditor, AJAX Save

后端 未结 10 1472
走了就别回头了
走了就别回头了 2021-01-03 01:22

Can you provide an example on how to setup CKEditor to save via AJAX using the Save button in the CKEditor toolbar?

I\'m interested in creating a CKEditor AJAX save

10条回答
  •  粉色の甜心
    2021-01-03 01:28

    More one solution variation, using AJAX from jQuery. 1) declare the function CKEDITOR.ajaxSAVE; 2) call it for save updated HTML of the textarea.

     CKEDITOR.ajaxSAVE = function ( editor ) {
        editor.updateElement();
        var htm = editor.getData();
        var otherParameter = '...';
        if (htm) $.ajax({
            type: "POST",
            url: "saveHtmFromCKEditor.php",
            data: { content: htm, other: otherParameter }
          }).done(function( msg ) { // string or JSON object
            if (!parseInt(msg)>0) alert( "ERROR WHEN SAVING: " + msg );
          });
        else 
          alert('EMPTY HTM. NOT SAVED');
     };
    

    Then, for call, at any time, use

     var oEditor = parent.main.CKEDITOR.instances['YourTextAreaID'];
     CKEDITOR.ajaxSAVE(oEditor);  
    

提交回复
热议问题