2014-05-20 43 views
1

我正在使用自定義窗體並使用ajax調用生成表單元素,但textarea未加載ckeditor。這裏是我的代碼:ckeditor未加載通過ajax調用生成的元素?

Ajax代碼:

jQuery.ajax({ 
    type: "POST", 
    url: "reg_arz_ajax2.php", 
    data: "book="+book_arzyabi, 
    dataType : "html", 
    success: function(response){ 

     $('#resp').html(response); 
    }, 
    error:function (xhr, ajaxOptions, thrownError){ 
     //On error, we alert user 
     alert(thrownError); 
    } 
}); 

$("#dialog-form").dialog("open"); 

}); 

Ajax響應是:

'<textarea class="ckeditor" cols="80" id="fname" name="fname" rows="10" >test</textarea>'; 

的html代碼:

<html> 
<head> 
<script type="text/javascript" src="../include/ckeditor/ckeditor.js"></script> 
<script type="text/javascript" src="../include/ckeditor/sample.js" ></script> 
</head> 

<body> 
<form> 
<fieldset> 
<label for="name">Name</label> 
<div id="resp" ></div> 
</fieldset> 
</form> 
</body> 
</html> 

請幫我解決了問題。

+0

它是否拋出任何錯誤?怎麼了? –

+0

不,只顯示沒有eceditor工具欄的textarea。 – user3656165

+0

粘貼將您的textareas轉換爲eceditor textareas的代碼。 –

回答

1

插入這些行:

ckeditor.replace('#fname'); // ADD THIS 
$('#fname').ckeditor(); // ADD THIS 

您的代碼應該是這樣的:

jQuery.ajax({ 
type: "POST", 
url: "reg_arz_ajax2.php", 
data: "book="+book_arzyabi, 
dataType : "html", 
success: function(response){ 

    $('#resp').html(response); 
    ckeditor.replace('#fname'); // ADD THIS 
    $('#fname').ckeditor(); // ADD THIS 
}, 
error:function (xhr, ajaxOptions, thrownError){ 
    //On error, we alert user 
    alert(thrownError); 
} 
}); 

$("#dialog-form").dialog("open"); 

}); 
+0

does not work !!! – user3656165

+0

你有什麼錯誤嗎? (如果你檢查螢火蟲例如) –

0

僅具有此行我工作:

ckeditor.replace('#fname'); 

和下面的行需要被刪除:

$('#fname').ckeditor(); // this does NOT work 

也注意,ckeditor需要在帽,所以:

CKEDITOR.replace('#fname'); 
0

只添加CKEDITOR.replace('fname');代替。 是沒有必要的。此外,您不必添加:

$('#fname').ckeditor(); 

確保它的整個大寫,如CKEDITOR不CKEDITOR

相關問題