简体   繁体   English

Trumboyg 不是一个函数 | Javascript 错误

[英]Trumbowyg is not a function | Javascript Error

I am working with the laravel framework and trumbowyg (javascript rich text editor, see: https://alex-d.github.io/Trumbowyg/ ).我正在使用 laravel 框架和 trumbowyg(javascript 富文本编辑器,请参阅: https ://alex-d.github.io/Trumbowyg/)。 I am building a page where the user can edit his post and save it immediatly after he change something.我正在构建一个页面,用户可以在其中编辑他的帖子并在他更改某些内容后立即保存。

To achieve my goal that the user must not reload the page I am using AJAX to save the changes, but I am getting the error "trumbowyg is not a function" each time I click on my save button.为了实现用户不得重新加载页面的目标,我使用 AJAX 来保存更改,但每次单击保存按钮时都会收到错误“trumbowyg 不是函数”。

This is my javascript code:这是我的 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);
            }
        });
    })


})

Is there anything I can do to fix this error?我能做些什么来修复这个错误?

The normal function: $('#editor').trumbowyg('html', '{!! $document->old_version !!}');普通函数: $('#editor').trumbowyg('html', '{!! $document->old_version !!}'); is working fine so the order of loading the javascript files should be correct, but the kind of this error speeks against this.工作正常,因此加载 javascript 文件的顺序应该是正确的,但是这种错误的类型与此相反。

Solution was adding $.noConflict();解决方案是添加$.noConflict(); to the first line after the definition of the function inside of the document ready call.到第一行定义好函数里面的文件后调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM