Error loading wp_editor via ajax in wordpress


I needed help. I’m creating a page external to wordpress and needed to add wp_editor. Here is a simplified example of my code:

<?   require('../wp-blog-header.php');   define('WP_USE_THEMES', false);   ...   <body>     <button onclick="get_editor_ajax()"></button>     <div id="editor_text"></div>     ...       function get_editor_ajax(){         ...         success: function(resp){           jQuery("#editor_text").html( resp );         }         ...       }     ...   </body> ?> 

function.php

function test_editor_text(){   wp_editor($  content, $  editor_id);   _WP_Editors::enqueue_scripts();   print_footer_scripts();   _WP_Editors::editor_js();   wp_die(); } add_action('wp_ajax_test_editor_text', 'test_editor_text'); 

Partly it’s working, but I have problems. 1st – clicking on the button “get_editor_ajax ()” makes the element below (attachment img) appear at the end of the page.

enter image description here

2nd – The add media button does not work. I believe it is because the necessary scripts are missing. One time, my page doesn’t use a theme, it doesn’t load wordpress scripts.

Note: When calling the get_editor_ajax () function more than once, I noticed that codes are being added before the closing of as in this other attached image.

enter image description here

I need help with these two problems. Thanks in advance.