Load wp_editor via ajax

时间:2012-09-18 作者:moettinger

Possible Duplicate:
How to load wp_editor() through AJAX/jQuery

我知道之前有人问过这个问题,但没有得到充分、准确或描述性的回答。我知道如何在页面加载时加载wp\\U编辑器,如下所示:

<?php wp_editor( $content, \'bio\', $settings = array() );  ?>
但当通过ajax加载编辑器时,这不起作用。

我的插件加载足球运动员列表。单击播放器时,页面上的包装器div将替换为该特定播放器的数据。其中一部分需要是wp\\u editor的实例。

包装器div替换为以下表单。表单中的最后一行需要加载wp\\U编辑器。

此jQuery将“tfb\\u replace”div替换为响应,在本例中,响应是一个表单。

$.post(ajaxurl, data, function(response) {
  $(\'.tfb_replace\').html(response);
});
以下是表格:

    <form method="POST" action="" name="edit_player_form" enctype="multipart/form-data"> 
    <table class="form-table">
        <tr valign="top">
            <th scope="row"><label for="player_pic">Profile Image</label></th>
            <td><input name="player_pic" value="<?php echo $object->player_pic; ?>" /></td>
        </tr>
        <tr valign="top">
            <th scope="row"><label for="player_height">Height</label></th>
            <td><input name="player_height" value="<?php echo $object->player_height; ?>" /></td>
        </tr>
        <tr valign="top">
            <th scope="row"><label for="player_weight">Weight</label></th>
            <td><input name="player_weight" value="<?php echo $object->player_weight; ?>" /></td>
        </tr>
        <tr valign="top">
            <th scope="row"><label for="player_year">Years in School</label></th>
            <td><input name="player_year" value="<?php echo $object->player_year; ?>" /></td>
        </tr>
        <tr valign="top">
            <th scope="row"><label for="player_position">Category</label></th>
            <td>
                <select name="player_cat">
                    <option value="<?php echo $object->player_cat; ?>"><?php echo $object->player_cat; ?></option>
                    <option value="Mayor">Mayor</option>
                    <option value="Intermedia">Intermedia</option>
                    <option value="Juvenil">Juvenil</option>
                </select>
            </td>
        </tr>
        <tr valign="top">
            <th scope="row"><label for="player_year">Bio</label></th>
            <td><!-- wp_editor would load here --></td>
        </tr>
    </table>
    <br/>
    <input type="button" name="edit" value="Save Edits" class="button-primary" />&nbsp;&nbsp;&nbsp;
    <input type="button" name="remove" value="Remove Player" class="button-primary" />
    <input type="hidden" name="player_id" value="<?php echo $object->id; ?>" />
</form>

1 个回复
SO网友:Chester Alan

将其添加到插件文件:(您也可以将其添加到主题的函数文件中)

function ajax_wp_editor()
{
     ?>
     your html form here
    <?php
}
//for all users
add_action(\'wp_ajax_nopriv_ajax_wp_editor\', \'ajax_wp_editor\');
// for logged in users
add_action(\'wp_ajax_ajax_wp_editor\', \'ajax_wp_editor\');
使用以下URL请求Ajax:

[BLOG_ADDRESS]/wp-admin/admin-ajax.php?action=ajax_wp_editor

结束

相关推荐

Tinymce broken after update

我已经找到了其他与此相关的帖子,但没有人能回答我的问题。更新到WP 3.4后,我的可视化编辑器已损坏。Firebug报告此错误Failed to load: http://xxxxxx.com/wp-includes/js/tinymce/langs/pt.js wp tin。。。9-20805(林哈1号)我试着将主题设置为默认主题,效果很好。那么,我有没有办法确定是什么导致了这种情况,以便修复它?