Okay so I spit through some existing themes I have to try and figure out how to achieve this. If anyone is reading this, this is how I did it:
In the onclick function of the TinyMCE I called the ajax form and then inside the form I added some javascript that uses the
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, output);
command to put text back into the editor. This is ofcourse triggered by some sort of submit button.
Then I use
tb_remove();
To close the thickbox again.
So essentially that would make the function look a bit like this:
add_action('wp_ajax_aes_ajax_test', 'aes_ajax_test');
function aes_ajax_test(){
?>
<script type="text/javascript">
jQuery('#aes-submit').click(function(){
tinyMCE.activeEditor.execCommand('mceInsertContent', 0, 'swag');
tb_remove();
})
</script>
<?php
echo '<button id="aes-submit">Submit Data</button>';
}