微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我使用Yii2,并且需要连接ckedit5,但是上传照片时出现错误-400错误请求

如何解决我使用Yii2,并且需要连接ckedit5,但是上传照片时出现错误-400错误请求

$(“。editor”)。each(function(){ 让id = $(this).attr('id'); 经典编辑器 .create(document.querySelector('#'+ id),{

            toolbar: [ 'heading','|','bold','italic','link','bulletedList','numberedList','blockQuote','imageUpload' ],ckfinder: {
            // Upload the images to the server using the CKFinder QuickUpload command.
             headers: {
               tokenUrl: '{$csrf_token}'
            },uploadUrl: '/admin/settings/ajax-upload-photo',},heading: {
                options: [
                    { model: 'paragraph',title: 'Paragraph',class: 'ck-heading_paragraph' },{ model: 'heading1',view: 'h1',title: 'heading 1',class: 'ck-heading_heading1' },{ model: 'heading2',view: 'h2',title: 'heading 2',class: 'ck-heading_heading2' }
                ]
            },})
        .then(function (editor) {
            console.log(editor);
        })
        .catch(function (error) {
            console.error(error);
        });
});

解决方法

请以html格式使用csrf()

<form>
<?= Html::hiddenInput(Yii::$app->request->csrfParam,Yii::$app->request->csrfToken); >
</form>

$(".editor").attr({
    type: 'hidden',name: '_csrf'
    value: $('meta[name=csrf-token]').attr("content");
}).appendTo('form');

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。