特朗博维格不是一个函数 |Javascript 错误



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

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

这是我的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();

最新更新