Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用编辑器作为ajax响应呈现wordpress表单工作不正常_Ajax_Wordpress_Editor - Fatal编程技术网

使用编辑器作为ajax响应呈现wordpress表单工作不正常

使用编辑器作为ajax响应呈现wordpress表单工作不正常,ajax,wordpress,editor,Ajax,Wordpress,Editor,在wordpress的一个项目中,我尝试创建一个带有不同字段的自定义主题选项。但是,当我尝试使用带有文本编辑器的ajax加载表单时,我遇到了一个问题。渲染编辑器出现样式和javascript问题,即文本颜色变为白色,编辑器按钮不可见,文本和视觉切换也不起作用。我想我需要运行一些javascript或者我错过了一些可以在呈现的html中调用的js文件,我附加了这个消息的屏幕截图,我的呈现html代码如下所示,这个表单在管理区域中被重新定义为内部html <form id="bgntheme_

在wordpress的一个项目中,我尝试创建一个带有不同字段的自定义主题选项。但是,当我尝试使用带有文本编辑器的ajax加载表单时,我遇到了一个问题。渲染编辑器出现样式和javascript问题,即文本颜色变为白色,编辑器按钮不可见,文本和视觉切换也不起作用。我想我需要运行一些javascript或者我错过了一些可以在呈现的html中调用的js文件,我附加了这个消息的屏幕截图,我的呈现html代码如下所示,这个表单在管理区域中被重新定义为内部html

<form id="bgntheme_option_form" action="#" method="post">
  <ul>
    <li class="li-first">
      <div class="option-field">Home Page Header</div>
      <div class="option-value">
        <?php
            $settings = array( 'textarea_name' => 'bgntheme_home_header' );         
            wp_editor( $content, $editor_id, $settings );        
        ?>
        <p class="field-info">Header textarea for homepage.</p>
      </div>
      <div class="clear-both"></div>
    </li>
    <li class="update-form">
      <button id="bgntheme_submit" name="general-settings-submit" value="Update-General" >Update</button>      
    </li>
  </ul>
</form>

  • 主页标题 主页的标题文本区域

  • 更新

您必须将以下代码片段添加到ajax成功方法中:

tinymce.execCommand('mceRemoveEditor', true, 'your_editor_id' );
tinymce.execCommand('mceAddEditor', true, 'your_editor_id' );
请用编辑器id替换
您的编辑器id

更新

您可以尝试以下方法:

1) HTML


我有你的问题,我解决了。 在javascript文件的回调函数中添加以下代码:

quicktags({id : 'your_editor_id'});
tinymce.execCommand( 'mceAddEditor', false, 'your_editor_id' );
hear就是一个例子:

$.ajax({
        url: data.ajax_url,
        type: 'post',
        datatype: 'json',
        success : function (response) {
            $('.row').append(String(response));
            quicktags({id : 'your_editor_id'});
            tinymce.execCommand( 'mceAddEditor', false, 'your_editor_id' );
            }
        });

这就是我在html$editor\u id=“your\u editor\u id”中所做的;$settings=array('textarea\u name'=>'bgntheme\u home\u header');wp_editor($content,$editor_id,$settings);在ajax响应成功中:函数(响应){jQuery('content wrapper inner').html(响应);jQuery('content wrapper inner').fadeIn(“slow”,function(){tinymce.execCommand('mceRemoveEditor',true,'your_editor_id');tinymce.execCommand('mceAddEditor',true,'your_editor_id'));}仍然不工作,是否我错过了其他内容首先您需要更新
您的编辑器id
它是您的编辑器id。编辑器id是正确的,我暂时在我的控制台中放置相同的“您的编辑器id”“未捕获引用错误:tinymce未定义”如果未工作,请使用其他选项暂停此链接
quicktags({id : 'your_editor_id'});
tinymce.execCommand( 'mceAddEditor', false, 'your_editor_id' );
$.ajax({
        url: data.ajax_url,
        type: 'post',
        datatype: 'json',
        success : function (response) {
            $('.row').append(String(response));
            quicktags({id : 'your_editor_id'});
            tinymce.execCommand( 'mceAddEditor', false, 'your_editor_id' );
            }
        });