Redirect users away from Admin breaks ajax

You can and a check for the DOING_AJAX constant which is defined on an Ajax in your conditional check:

function no_admin_access()
{
    if (
        // Don't do this for AJAX calls
        ! defined( 'DOING_AJAX' ) 
        // Capability check
        && ! current_user_can( 'delete_posts' ) 
        )
    {
        // Redirect to home/front page
        wp_redirect( site_url( "https://wordpress.stackexchange.com/" ) );
        // Never ever(!) forget to exit(); or die(); after a redirect
        exit;
    }
}
add_action( 'admin_init', 'no_admin_access' );

tech