1

I have a web form that I'm $.posting that contains a CKEditor textarea.

    $(document).ready(function() {

        CKEDITOR.replace('html');
        CKEDITOR.config.htmlEncodeOutput = true; //seems to have no effect

        $('#save').click(function() {            

            $.post('/async.php?a=save-slide', $('#slideForm').serialize(),
            function(json) {
                console.log(json);
            }, 'json');
        });            
    });

I have two problems:

  1. .serialize() isn't getting the CKEditor contents. If I console.log the serialized string, html= is empty.
  2. If I use the CKEditor getData() method and there is an ampersand ( ) in the POSTed content, my script breaks because it's making an XML-based API call.

Any ideas on how I can get the contents and safely POST xml-friendly data?

doremi
  • 14,921
  • 30
  • 93
  • 148

1 Answers1

1

I use the following generic method to move ckeditor contents back into the text area they were attached to:

   var $editors = $("textarea.editor");
   if ($editors.length) {
       $editors.each(function () {
           var instance = CKEDITOR.instances[this.id];
           if (instance) { $(this).val(instance.getData()); }
       });
   }

If your situation is simpler there is no need for the loop.

There is also the jquery helper that is handy for this sort of thing.

ScottE
  • 21,530
  • 18
  • 94
  • 131
  • I can use getData, but I need it to be html encoded and the config option that is present in my code doesn't seem to be working. – doremi Dec 09 '11 at 02:00