duanbin4847 2016-10-10 17:22
浏览 113
已采纳

使用ckeditor内联编辑后,没有运气保存数据

I'm trying to build an article system, where the content divs can be edited inline with ckeditor. The number of content divs is variable, so an article has for example two divs:

<div id="content_11439" contenteditable="true">Click to edit.</div>
<div id="content_11440" contenteditable="true">Click to edit.</div>

Now I have already browsed the forums, and have tried incorporating some answers into my solution for saving the text to my database. The inline editing part works, ckeditor shows and I can edit, but it seems like my code isn't being send to the php-file that should save it once I click somewhere else on the page and ckeditor closes.

The following code comes from these forums:

<script type="template" data-sample="1">

CKEDITOR.disableAutoInline = true;

$("div[contenteditable='true']" ).each(function( index ) {

    var content_id = $(this).attr('id');

    CKEDITOR.inline( content_id, {
        on: {
            blur: function( event ) {
                var data = event.editor.getData();

                var request = jQuery.ajax({
                    url: "http://www.xxxxxx/saveTextDetails.php",
                    type: "POST",
                    data: {
                        content : data,
                        content_id : content_id
                    },
                    dataType: "html"
                });

            }
        }
    } );

});

Jquery is loaded, I don't get any errors in my console, but I don't get any post-requests either, while I did manage to do about the same thing on a different page, to save the text in an input form when clicking a save button.

Thank you for your help.

  • 写回答

1条回答 默认 最新

  • douyun1852 2016-10-11 00:10
    关注

    Your problem was with data-sample="1" inside the <script> tag, which caused the script inside that tag to not run (which means the divs got automatically the ckeditor, and by CKEDITOR.inline( content_id.

    Check this:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script src="http://cdn.ckeditor.com/4.4.7/standard/ckeditor.js"></script>
    
    <div id="content_11439" contenteditable="true">Click to edit.</div>
    <div id="content_11440" contenteditable="true">Click to edit.</div>
    <script>
      CKEDITOR.disableAutoInline = true;
      $("div[contenteditable='true']" ).each(function( index ) {
        var content_id = $(this).attr('id');
        CKEDITOR.inline( content_id, {
          on: {
            blur: function( event ) {
              var data = event.editor.getData();
              alert("Sending: " + data)
              /*
              var request = jQuery.ajax({
                url: "http://www.xxxxxx/saveTextDetails.php",
                type: "POST",
                data: {
                  content : data,
                  content_id : content_id
                },
                dataType: "html"
              });
              */
            }
          }
        } );
      });
    </script>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。