Loading a sidebar on an Ajax call

is_admin() returns true if you’re doing an Ajax request. So this is why my code didn’t work. Instead I’ve done this:

add_filter( 'loop_start', 'my_sidebar_widget', 25 );

function my_sidebar_widget() {
    if ( is_active_sidebar( 'my_sidebar' ) && (defined( 'DOING_AJAX' ) && DOING_AJAX ) || !is_admin() ) { 
        echo '<div id="my_sidebar">';
        dynamic_sidebar('my_sidebar');
        echo '</div>';

    }
}

defined( 'DOING_AJAX' ) && DOING_AJAX returns true if you’re doing an Ajax call, and !is_admin will work if you’re not doing an Ajax request. In this way, it is not shown in the Media Admin Panel.