首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ck编辑器的文本区域在向ajax laravel和jQuery发送数据时返回一个空值。

使用ck编辑器的文本区域在向ajax laravel和jQuery发送数据时返回一个空值。
EN

Stack Overflow用户
提问于 2022-09-26 10:48:41
回答 2查看 162关注 0票数 0

在表单的文本区域,我集成了CK编辑器,它很好地显示了文本区域中的编辑器,但是问题是当我在文本区域中添加值并尝试通过ajax发送它时,我得到一个空值被发送。但当我删除ck编辑器代码时,代码将被发送。我可能在这里错过了什么?

单击“创建策略”按钮时,将调用addeitpolicymodal。//增加一项新政策

代码语言:javascript
运行
复制
  $(document).on('click','#createpolicy',function(){
     $('#addeditpolicymodal').modal('toggle');
     $('.addeditpolicy_title').html('Add A new Policy');
     $('#savepolicy').html('Create the Policy');
     // integrate ck editor
     $("#policy_description_ck").html('<textarea class="form-control text-white bg-dark policydesceditor" name="policy_description" placeholder="Describe the Policy Details here.explain it with as more details as possible"></textarea>');
     ClassicEditor
     .create( document.querySelector( '.policydesceditor' ),
     {
        toolbar: {
           items: [
              'heading', '|',
              'bold', 'italic', '|',
              'link', '|',
              'outdent', 'indent', '|',
              'bulletedList', 'numberedList', '|',
              'undo', 'redo'
           ],
           shouldNotGroupWhenFull: true
        }
     })
     $("#addremovevideo").hide();
  });

下面是我发送数据的ajax代码:

代码语言:javascript
运行
复制
$('#savepolicy').click(function(e){
        e.preventDefault();
        var policyid=$('#policyid').val();
        var url = '{{ route("createupdate.policy", ":id") }}'; 
        policyupdateurl = url.replace(':id',policyid);

        var form = $('#addeditpolicyform')[0];
        var formdata=new FormData(form);

        $.ajax({
           url:policyupdateurl,
           method:'POST',
           processData:false,
           contentType:false,
           data:formdata,
           success:function(response)
           {
              console.log(response);
              if (response.status==400)
              {
                 $('.policy_errorlist').html(" ");
                 $('.policy_errorlist').removeClass('d-none');
                 $.each(response.message,function(key,err_value)
                 {
                    $('.policy_errorlist').append('<li>' + err_value + '</li>');
                 })
              } else if (response.status==200)
              {
                    alertify.set('notifier','position', 'top-right');
                    alertify.success(response.message);
                    policycatstable.ajax.reload();
                    $('.addeditcatpolicy').html('');
                    $('.catlabel').html('');
                    $('.save_button').html('');
                    $('.policycat_id').val('');
                    $('#policycat_title').val('');
                    $('.adminaddeditpolicy').modal('hide');
              }
            });
          });
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-09-26 11:10:54

请在下面找到您的代码中的更改。

代码语言:javascript
运行
复制
$('#savepolicy').click(function(e){
        e.preventDefault();
        var policyid=$('#policyid').val();
        var url = '{{ route("createupdate.policy", ":id") }}'; 
        policyupdateurl = url.replace(':id',policyid);

        var form = $('#addeditpolicyform')[0];
        var formdata=new FormData(form);
        formdata.policy_description = CKEDITOR.instances['policy_description'].getData();
    

        $.ajax({
           url:policyupdateurl,
           method:'POST',
           processData:false,
           contentType:false,
           data:formdata,
           success:function(response)
           {
              console.log(response);
              if (response.status==400)
              {
                 $('.policy_errorlist').html(" ");
                 $('.policy_errorlist').removeClass('d-none');
                 $.each(response.message,function(key,err_value)
                 {
                    $('.policy_errorlist').append('<li>' + err_value + '</li>');
                 })
              } else if (response.status==200)
              {
                    alertify.set('notifier','position', 'top-right');
                    alertify.success(response.message);
                    policycatstable.ajax.reload();
                    $('.addeditcatpolicy').html('');
                    $('.catlabel').html('');
                    $('.save_button').html('');
                    $('.policycat_id').val('');
                    $('#policycat_title').val('');
                    $('.adminaddeditpolicy').modal('hide');
              }
            });
          });
票数 1
EN

Stack Overflow用户

发布于 2022-11-14 15:53:06

代码语言:javascript
运行
复制
   let editor;
    
ClassicEditor
    .create( document.querySelector( '#editor' ) )
    .then( newEditor => {
        editor = newEditor;
    } )
    .catch( error => {
        console.error( error );
    } );

// Assuming there is a <button id="submit">Submit</button> in your application.
document.querySelector( '#submit' ).addEventListener( 'click', () => {
    const editorData = editor.getData();

    // ...

} );

我对CkEditor 5进行更新。

https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/saving-data.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73853056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档