Trumbowyg 不是函数 | Javascript 错误

Trumbowyg is not a function | Javascript Error

我正在使用 laravel 框架和 trumbowyg(javascript 富文本编辑器,参见:https://alex-d.github.io/Trumbowyg/)。我正在构建一个页面,用户可以在其中编辑他的 post 并在他更改某些内容后立即保存它。

为了实现用户不得重新加载页面的目标,我正在使用 AJAX 来保存更改,但每次单击保存按钮时都会收到错误 "trumbowyg is not a function"。

这是我的 javascript 代码:

$(document).ready(function(){
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': "{{ csrf_token() }}"
        }
    });

    $(document).on('click', '#save', function(){
        $.ajax({
            method: 'POST',
            url: '/user/documents/{{$document->id}}/edit',
            data: {
                'created_post': $('#editor').trumbowyg('html'),
            },
            success: function(response){ 
                console.log(response);
            },
            error: function(jqXHR, textStatus, errorThrown){ 
                console.log(JSON.stringify(jqXHR));
                console.log("AJAX error: " + textStatus + + ' : ' + errorThrown);
            }
        });
    })


})

有什么办法可以解决这个错误吗?

正常功能:$('#editor').trumbowyg('html', '{!! $document->old_version !!}'); 工作正常,因此加载 javascript 文件的顺序应该是正确的,但这种错误与此相反。

解决方案是在文档就绪调用中函数定义后的第一行添加 $.noConflict();