2011-12-09 69 views
1

我有一個web表單,我$ .posting包含一個CKEditor textarea。發佈CKEditor內容

$(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'); 
     });    
    }); 

我有兩個問題:

  1. .serialize()是沒有得到CKEditor的內容。如果我console.log 序列化的字符串,html =是空的。
  2. 如果我使用CKEditor的getData()方法,並且在POST內容中有一個和號( ),我的腳本因爲它正在進行基於XML的API調用而中斷。

關於如何獲取內容和安全POST xml友好數據的任何想法?

回答

1

我用下面的泛型方法來移動CKEditor的內容迴文本區域,他們連接到:

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

如果您的情況比較簡單,不需要進行循環。

還有jquery助手,這種事情很方便。

+0

我可以使用getData,但我需要它是HTML編碼,並在我的代碼中存在的配置選項似乎並沒有工作。 – doremi

+0

http://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding – ScottE