Reputation: 26762
I'm using CKEditor to change my textareas into a wysiwyg. It all works fine, except when i load content through an Ajax call. Then my CKEditor doesn't load.
I've searched for a solution, but couldn't find any that worked for me.
My Ajax call basically looks like this:
$.ajax({
type: "POST",
url: url,
success: function(data) {
$('#content').html(data);
$('.ckeditor').ckeditor();
}
});
As you can see i tried to use the function ckeditor() to programmatically load the CKEditor. But this gives me the following error:
FireFox says:
$(".ckeditor").ckeditor is not a function
And IE says:
Object doesn't support property or method 'ckeditor'
Is there any other way to load the CKEditor by class name when the content is loaded through an Ajax call??
Upvotes: 6
Views: 13385
Reputation: 41
You can use done()
and then()
methods after ajax
$.ajax({
type: "POST",
url: url
}).done(function(data){
$('#content').html(data);
}).then(function(){
$('.ckeditor').ckeditor();
});
Upvotes: 0
Reputation: 161
Had a simlar issue. I needed multiple areas with CKEDITOR after AJAX + appending elements to the page (those with editable properties). Spent a ton of hours to no avail and then...
I found this and added it AFTER setting contenteditable to true in those elements:
CKEDITOR.inlineAll();
Handled initializing all my CKEDITOR areas AFTER AJAX + append to page.
https://docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR-method-inline
Upvotes: 1
Reputation: 164
I tried the accepted answer by calling
$('.ckeditor').ckeditor();
in my ajax's success propery. Yet this gave an error.
StanleyD's answer however did work.
After appending your content with ajax, try adding the following code within the ajax's success property:
CKEDITOR.replace('textareaId');
Upvotes: 1
Reputation: 2368
you can use command:
CKEDITOR.replace( 'editor1' );
but with one difference - editor1 is the id of the textarea and not the class.
Upvotes: 4
Reputation: 71
First you have to load the jquery adapter '/path/to/ckeditor/adapters/jquery.js'
Than $('.ckeditor').ckeditor();
will work.
Upvotes: 7
Reputation: 35572
there is a way around to this. load your ckeditor as usual, but keep it hidden. and when contents are loaded through ajax populate the editor div and display through jquery.
Upvotes: 2