[英]wp_editor() in content that was loaded with ajax
I try to use wp_editor()
in content that was loaded with ajax, but none of the required files and some other configuration script not loaded : 我尝试在用ajax加载的内容中使用
wp_editor()
,但没有加载任何必需的文件和一些其他配置脚本:
The structure of ajax is something like this: ajax的结构是这样的:
function get_test_page(){
include( TEMPLATEPATH . '/page.php' );
die( main() );
}
add_action( 'wp_ajax_nopriv_get_test_page', 'get_test_page' );
add_action( 'wp_ajax_get_test_page', 'get_test_page' );
page.php : page.php:
function main(){
wp_editor('','unique_id');
}
Editor is loaded but needed files is not loaded. 编辑器已加载,但所需文件未加载。
http://.../wp-includes/js/tinymce/wp-tinymce.php
http://.../wp-includes/js/tinymce/skins/lightgray/skin.min.css
http://.../wp-admin/load-scripts.php?c=1&load%5B%5D=...mce-view,imgareaselect,image-edit,word-count,editor,quicktags,wplink,thick..
http://.../wp-includes/js/tinymce/langs/{}.js
...
Some related post but doesn't help me : 一些相关的帖子,但对我没有帮助:
use wordpress wp_editor in dynamic/ajax html 在动态/ ajax html中使用wordpress wp_editor
How to load wp_editor() through AJAX/jQuery 如何通过AJAX / jQuery加载wp_editor()
Solution : 解决方案 :
Add wp_editor()
in somewhere that works perfectly and hide it. 将
wp_editor()
添加到最wp_editor()
并将其隐藏。
<div class="hidden-editor-container" style="display:none;">
<?php wp_editor( '', 'editor' ); ?>
</div>
after that assign editor contents to the global JS variable. 之后,将编辑器内容分配给全局JS变量。
EDITOR = $('.hidden-editor-container').contents();
Finally when the ajax page is loaded append editor contents 最后,当加载ajax页面时,追加编辑器内容
$('.editor').append( EDITOR );
tinymce.execCommand( 'mceRemoveEditor', false, 'editor' );
tinymce.execCommand( 'mceAddEditor', false, 'editor' );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.