Javascript TinyMCE uploadImages()函数不起作用
我正在尝试使用TinyMCE作为所见即所得编辑器。但是,当我尝试将图像上载到我的服务器时,会出现一个错误,该错误指出: 无法读取未定义的属性“uploadImages” 我正在阅读确切的文档,但由于某些原因,它无法识别该函数。这是我的密码:Javascript TinyMCE uploadImages()函数不起作用,javascript,jquery,tinymce,Javascript,Jquery,Tinymce,我正在尝试使用TinyMCE作为所见即所得编辑器。但是,当我尝试将图像上载到我的服务器时,会出现一个错误,该错误指出: 无法读取未定义的属性“uploadImages” 我正在阅读确切的文档,但由于某些原因,它无法识别该函数。这是我的密码: <!DOCTYPE html> <html> <head> <link href="resources/css/index.css" rel="stylesheet" type="text/css">
<!DOCTYPE html>
<html>
<head>
<link href="resources/css/index.css" rel="stylesheet" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
</head>
<body>
<div id="container">
<form>
<label>Title</label>
<input type="text" name="title">
<label>Description</label>
<input type="text" name="desct">
<textarea id="editor"></textarea>
<input type="submit">
</form>
</div>
</body>
<script>
tinymce.init({
selector: '#editor',
theme: 'modern',
browser_spellcheck: true,
height: 480,
images_upload_url: 'resources/scripts/postAcceptor.php',
images_upload_base_path: '/tutorials/resources/images/',
images_upload_handler: function (blobInfo, success, failure) {
this.activeEditor.uploadImages(function(success) {
$.post('resources/scripts/postAcceptor.php', this.activeEditor.getContent()).done(function() {
console.log("Uploaded images and posted content as an ajax request.");
});
});
},
plugins: [
'advlist autolink link code image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality emoticons template paste textcolor'
],
toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage | forecolor backcolor emoticons | fontselect'
});
</script>
</html>
错误在于,在images\u upload\u handler键中的函数中,代码试图获取this.activeEditor,但该变量返回未定义 基于此文档,它应该是tinymce.activeEditor
附言:我不确定你想做什么。如果我理解正确,您不应该执行post方法,它应该自己执行,您应该只发送一个函数,该函数将在post成功或失败后执行。如果将post方法放在该处理程序中,可能会上载两次。看看功能齐全的演示:我正在尝试这样做:uploadImages功能根本不起作用。我只是想把用户上传的图像发送到服务器上。@user2896120哦,我明白了,但是在这个例子中,它并没有通过JSON配置,它看起来像是在所有东西之外。他将函数发送到tinymce.activeEditor.uploadImages方法
images_upload_handler: function (blobInfo, success, failure) {
this.activeEditor.uploadImages(function(success) {
$.post('resources/scripts/postAcceptor.php', this.activeEditor.getContent()).done(function() {
console.log("Uploaded images and posted content as an ajax request.");
});
});
},