简体   繁体   English

使用ajax保存时,ckeditor无法发布结果

[英]ckeditor fails to post results when with ajax save

I have a form set up to do a dynamic save with ajax. 我设置了一个表格来使用ajax进行动态保存。 It works great with a standard textarea but after enabling ckeditor using the ckeditor class it does not respond. 它适用于标准文本区域,但是使用ckeditor类启用ckeditor后,它不会响应。 The form looks like: 该表格如下所示:

<div class="form-group">
  <div class="float auto clear">
    <textarea class="ckeditor saveData" name="introtext" itemid="<?php echo $id; ?>" id="editor1" ><?php echo "$introtext"; ?></textarea>
  </div>
</div>

ckeditor is the class ckeditor uses to load the editor. ckeditor是ckeditor用于加载编辑器的类。 saveData is the class I use to initiate the javascript function to save the textarea data. saveData是我用来启动javascript函数以保存textarea数据的类。 The javascript: JavaScript:

// ckeditor textarea
$(document).on('keyup','.saveData',function()
{
  var DATA = CKEDITOR.instances.editor1.getData();
  var cleaned=remove_whitespaces(DATA);
  var ID=$(this).attr('itemid');
  if(cleaned !=''){
    var dataString = 'introtext='+ cleaned  +'&id='+ ID;
    $.ajax({
      type: "POST",
      url: "save.php",
      data: dataString,
      cache: false
    });
  }
})
// END SAVE BASE


// ordinary textarea
$(document).on('keyup','.saveData2',function()
{
  var DATA=$(this).val();
  var cleaned=remove_whitespaces(DATA);
  var ID=$(this).attr('itemid');
  if(cleaned !=''){
      var dataString = 'introtext2='+ cleaned  +'&id='+ ID;
    $.ajax({
      type: "POST",
      url: "save.php",
      data: dataString,
      cache: false
    });
  }
})

You can see the form at www.dottedi.us/ckeditor. 您可以在www.dottedi.us/ckeditor上查看该表格。 I tried using both: 我尝试同时使用:

var DATA=$(this).val();

and

var DATA = CKEDITOR.instances.editor1.getData();

but neither work. 但都不起作用。

Try using the below- 尝试使用以下-

<div class="form-group">
  <div class="float auto clear">
    <textarea class="ckeditor saveData" name="introtext" itemid="<?php echo $id; ?>" id="editor1" ><?php echo "$introtext"; ?></textarea>
  </div>
</div>

// ckeditor textarea
var editor = CKEDITOR.replace('editor1');
editor.on('change', function()
{
  var DATA = this.getData();
  var cleaned=remove_whitespaces(DATA);
  var ID=$('#editor1').attr('itemid');
  if(cleaned !=''){
    var dataString = 'introtext='+ cleaned  +'&id='+ ID;
    $.ajax({
      type: "POST",
      url: "save.php",
      data: dataString,
      cache: false
    });
  }
})
// END SAVE BASE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM