After ajax form submit value from ckeditor textarea is not sent via message

I have a form that has some text fields and a text field (ckeditor), after the value of the art_title field of the onclick button is sent to the art_save.php page, but the value from textarea is not submitted.

<script src="ckeditor/ckeditor.js"></script>
function saveArt() 
{
    var title = document.getElementById('art_title'),
        art_title = title.value;

    var desc = document.getElementById('art_body'),
        art_body = desc.value;

    jQuery.ajax({
        type: 'POST',
        url: 'art_save.php',
        data: {
            title: art_title,
            aut: art_author,
            tag: art_tag,
            desc: art_body

              }

         });  
         return false; 

 }

html part

<form method="post" name="art" id="art">
    <input type="text" id="art_title" name="art_title" placeholder="Here goes your title"/>
<textarea class="ckeditor" name="art_body" id="art_body"></textarea>
<input type="submit" name="savedraft" id="savedraft" onclick="saveArt();return false;" value="Need more Research ! Save as Draft" class="button"/>
</form>
+4
source share
4 answers

You can force CKeditor to update the textarea value using:

for (instance in CKEDITOR.instances) {
    CKEDITOR.instances[instance].updateElement();
}

In addition, you can use .serializefor data - then you do not have to support AJAX code if the parameters change:

<script src="ckeditor/ckeditor.js"></script>
function saveArt() 
{
    for (instance in CKEDITOR.instances) {
        CKEDITOR.instances[instance].updateElement();
    }

    jQuery.ajax({
        type: 'POST',
        url: 'art_save.php',
        data: $("#art").serialize()
     });  
     return false; 

 }
+14
source
for (instance in CKEDITOR.instances) 
{
    CKEDITOR.instances[instance].updateElement();
}

$.ajax({
    url: "controllers/c.publicidad.php?task=save",
    type: 'post',
    data: $("form[name='form']").serialize(),
    dataType: 'json',
    success: function(data) {
        if(data.idenvio != ''){
            $("form[name='frmPublicidad']").toggle("slow");
            $("#MessageSuscripcion").html(data.message);
        }
    }
});
+1
source

html- ckeditor :

var art_body = CKEDITOR.instances.art_body.getData();
0

, :

$.ajax(
{
  type: "POST",
  url: path+"/html-action",
  data: {data1: dataone,
        data2: datatwo,
        data3: datathree,
        data4: datafour,
        message: ckeditortxt},
  cache: true,
  success: function(html)
  {
}
}

At first I used data to transfer data, but for some reason, the element that stores the ckeditor data is not considered as a parameter. Therefore, I divided all the parameters into separate components, that is, data1 data2, data3, data4 .... and this time it worked

0
source

Source: https://habr.com/ru/post/1589441/


All Articles