user3656165
user3656165

Reputation: 39

ckeditor not loading on element generated via ajax call?

I am using custom form and generating form elements with ajax call but textarea is not loaded with ckeditor. Here is my code:

ajax code:

    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 response is:

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

html code:

  <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>

Please help me for resolve problem.

Upvotes: 2

Views: 5704

Answers (5)

muratbaha
muratbaha

Reputation: 1

Edit this lines:

CKEDITOR.replace( 'fname' );

Your code should look like 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' ); //this line should be changed like this
    $('#fname').ckeditor();
},
error:function (xhr, ajaxOptions, thrownError){
    //On error, we alert user
    alert(thrownError);
}
});

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

});

Upvotes: 0

Reyza Permana S
Reyza Permana S

Reputation: 64

don't add ckeditor.replace('#fname'); you have to add $('#fname').ckeditor(); and in my project is works

Upvotes: 0

Olu Adeyemo
Olu Adeyemo

Reputation: 883

Add only CKEDITOR.replace('fname'); instead. The # is not necessary. Also, you do not have to add:

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

Make sure it's uppercase throughout, eg CKEDITOR not ckeditor

Upvotes: 1

kneidels
kneidels

Reputation: 914

for me having only this line worked:

ckeditor.replace('#fname');

and the following line needs to be REMOVED:

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

also note, that ckeditor needs to be in caps, so:

CKEDITOR.replace('#fname');

Upvotes: 2

Viktor Svensson
Viktor Svensson

Reputation: 755

Insert these lines:

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

Your code should look like 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");

});

Upvotes: 2

Related Questions