2014-08-31 88 views
2

我已將CKEDITOR併入我的網站。我希望它從數據庫加載內容,以便它可以被編輯。我可以使用ajax輕鬆地將數據從編輯器保存到數據庫。然而,當編輯首創負載我在鉻控制檯得到一個錯誤:將數據庫內容加載到ckeditor的textarea中

Uncaught SyntaxError: Unexpected token ILLEGAL

這點我在我的jQuery代碼的地方:

enter image description here

contentEditor.append('<div class="content-top-container"><div class="course-name"><div class="section-title">Title: <?php echo $this->section_title; ?></div><img id="close-<?=$this->c_id;?><?php echo $this->section_num; ?>" class="close-editor" src="../skins/blues/images/red-ex.png" title="Close" /></div></div><br /><textarea class="editor-area" id="<?php echo $this->c_id; ?>-<?php echo $this->section_num; ?>-editor" name="<?php echo $this->section_num; ?>-editor">'+innerTextArea+'</textarea>'); 
    CKEDITOR.replace('<?php echo $this->c_id; ?>-<?php echo $this->section_num; ?>-editor', { 
     toolbar : 'Full', 
     width : "1020px" 
    }); 

數據被存儲爲數據庫中的HTML。我相信正在發生的事情是,從數據庫返回的字符串會很長,並且Javascript會引發語法錯誤。我怎樣才能解決這個問題?我幾乎沒有CKEditor的經驗......先謝謝了!

回答

1

只是編碼字符串正確

var innerTextArea = <?php echo json_encode($inner->TextArea) ?>; 
+0

謝謝@Musa - 答案工作。乾杯 – massimorai 2014-09-01 11:48:46