Warm tip: This article is reproduced from serverfault.com, please click

Get value of textarea using ckeditor, Ajax

发布于 2020-12-11 19:31:53

I have this form for a blog. It works well with ajax no refresh, just serialize and submit data. Then i decided using ckeditor 5 the value of the textarea isnt submitted.

my ajax script

$(document).ready(function(){
    $("#create").click(function(event) {
        event.preventDefault();

        var form = $("#mytest");
        var formData = new FormData($("#mytest")[0]);
        $.ajax({
          url  : "test3.php",
          type : "POST",
          cache: false,
          contentType : false,
          processData: false,
          data: formData,
          success:function(response){
            $(".test").html(response);
          }
        });
    });
});

my html form

<form id="mytest" action="">
    <input type="number" name="number" value="">
    <br>
    <textarea class="editor" name="textarea"></textarea>
    <input type="submit" id="create" value="submit content">
</form>

<p class="test"></p>

my php code

$textarea = $_POST["textarea"];
$number = $_POST["number"];

echo $textarea;
echo $number;
Questioner
Everything good
Viewed
0
user2463644 2020-12-12 20:10:15

CKEditor wraps textarea in its own html markup, so in order to get that textarea text try:

$('.ck-content p').text();

In one of the earlier CKEditor versions I do

$('iframe').content().find('body').text();