在表单的文本区域,我集成了CK编辑器,它很好地显示了文本区域中的编辑器,但是问题是当我在文本区域中添加值并尝试通过ajax发送它时,我得到一个空值被发送。但当我删除ck编辑器代码时,代码将被发送。我可能在这里错过了什么?
单击“创建策略”按钮时,将调用addeitpolicymodal。//增加一项新政策
$(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代码:
$('#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');
}
});
});发布于 2022-09-26 11:10:54
请在下面找到您的代码中的更改。
$('#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');
}
});
});发布于 2022-11-14 15:53:06
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
https://stackoverflow.com/questions/73853056
复制相似问题