我正在使用laravel框架和trumbowyg (javascript富文本编辑器,参见:https://alex-d.github.io/Trumbowyg/)。我正在建立一个页面,在那里用户可以编辑他的帖子,并保存后,他更改了一些东西。
为了实现用户不能重新加载页面的目标,我使用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文件的顺序应该是正确的,但这种错误与此相反。
发布于 2019-06-25 19:35:56
解决方案是将$.noConflict();添加到文档就绪调用中函数定义之后的第一行。
https://stackoverflow.com/questions/56733504
复制相似问题