Create wp_editor with ajax call
-
Hi,
I am working on admin interface which have multiple wp_editor and we can add or remove an textarea.
When i load the page, i have a list of textareas with editors. When i click the add button, i call admin-ajx.php which call this function :
function ajax_create_settings_field_slider_image(){ $nonce = $_POST['nonce']; if (!wp_verify_nonce($nonce, 'ajax-nonce')) die ('Error!'); if (current_user_can('edit_theme_options')) { // Create editor if (isset($_POST['id']) && isset($_POST['option_name']) && isset($_POST['name']) && isset($_POST['index'])) { echo wp_editor('', 'custom-editor-' . $_POST['index'], array( 'media_buttons' => FALSE, 'textarea_name' => $_POST['option_name'] . '[' . $_POST['name'] .'][text][]', 'textarea_rows' => 5, 'wpautop' => FALSE )); } } exit; }
And this my Javascript Code :
jQuery.ajax({ type: 'POST', dataType: 'HTML', url: url, data: { 'action': 'create_settings_field_slider_image', 'limit' : limit, 'id' : id, 'option_name' : option_name, 'name' : name, 'index': nextId, 'nonce' : nonce }, success:function(data){ // Prepare parent and add data parent.find('.buttonAdd').hide(); parent.find('.buttonDelete').show(); parent.append(jQuery(data).html()); tinyMCE.execCommand('mceAddControl', false, 'custom-editor-' + nextId); }, error: function(errorThrown){ alert("Une erreur est apparue pendant l'ajout des nouveaux champs de saisies"); } });
Ajax call works fine, but my new editor don’t work, my TinyMCE buttons are not displayed, and when i click on Text or Visual link i have TinyMEC errors like : this.getDoc(…) is undefined, z is undefined
I try many things on my javascript like :
//init quicktags quicktags({id : 'custom-editor-' + nextId}); //init tinymce tinymce.init(tinyMCEPreInit.mceInit['custom-editor-' + nextId]);
but it’s never work.
Anyone can help me ?
Thanks
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Create wp_editor with ajax call’ is closed to new replies.