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:

function.php

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.