[英]wp_editor() in content that was loaded with ajax
我嘗試在用ajax加載的內容中使用wp_editor()
,但沒有加載任何必需的文件和一些其他配置腳本:
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:
function main(){
wp_editor('','unique_id');
}
編輯器已加載,但所需文件未加載。
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
...
一些相關的帖子,但對我沒有幫助:
解決方案 :
將wp_editor()
添加到最wp_editor()
並將其隱藏。
<div class="hidden-editor-container" style="display:none;">
<?php wp_editor( '', 'editor' ); ?>
</div>
之后,將編輯器內容分配給全局JS變量。
EDITOR = $('.hidden-editor-container').contents();
最后,當加載ajax頁面時,追加編輯器內容
$('.editor').append( EDITOR );
tinymce.execCommand( 'mceRemoveEditor', false, 'editor' );
tinymce.execCommand( 'mceAddEditor', false, 'editor' );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.