after ajax form submit value from ckeditor textarea is not sent through post

我们两清 提交于 2019-12-05 15:11:42

问题


i have a form having some textfields and a textarea (ckeditor), after onclick button art_title field value is sent to art_save.php page, but value from textarea is not sent.

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

回答1:


You can force CKeditor to update the textarea value using:

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

Also, you can use .serialize for the data - then you won't have to maintain the AJAX code if 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; 

 }



回答2:


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);
        }
    }
});



回答3:


you can get html form ckeditor with this :

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



回答4:


This is what worked for me:

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

Initially, I was using a datastring to pass information, but for some reason, the element that holds the ckeditor data was not being considered as a parameter. So I split all the parameters to individual components i.e. data1 data2, data3, data4.... and this time, it worked



来源:https://stackoverflow.com/questions/30397904/after-ajax-form-submit-value-from-ckeditor-textarea-is-not-sent-through-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!