How to reload a php script, using AJAX and jQuery

Good afternoon, I am a beginner in WordPress and I would like some advice.
I have a php script that loads some random article thumbnails according to some parameters.

5, 'orderby' => 'rand', 'meta_query' => array( array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ), ) ); $query = new WP_Query($posts); while($query->have_posts()) : $query->the_post(); ?> '; echo get_the_post_thumbnail( $_post->ID, 'thumbnail' ); echo '
'; ?>

It is found in wp-content themes children's theme parts logos.php
and loaded in my footer.php


The result works quite well, but now I would like it to be updated automatically every x seconds.
So I looked for a method to do it and I found this topic:
https://stackoverflow.com/questions/48440723/wordpress-auto-refresh-specific-div
And so, here is my script:

jQuery(function($) {
var refresh = function(){
  $("#logos").fadeOut("slow").load("/wp-content/themes/capitaine/parts/logos.php").fadeIn("slow");

}
setInterval(refresh, 3000 );  ///////// 30 seconds
 });

I have included it in my functions.php

wp_enqueue_script(
        'jquery',
        'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js',
        false,
        '3.3.1',
        true
    );
wp_enqueue_script(
    'refresh',
    get_template_directory_uri() . '/js/script.js',
    array( 'jquery' ),
    '1.0',
    true
);

But then I received this error

enter the description of the image here

The only way I've found to organize this is from this topic: https://stackoverflow.com/questions/39219396/need-to-run-wp-query-on-a-separate-php-file-for-an -ajax-call

I've added at the top of my script and it is working, but not according to the CSS that I have defined.
So here are my questions:
Is that method good?
If not, I would take any good advice.
And if it's okay, I would know why he is no longer in line with the CSS.

e.g.
Before recharging:
enter the description of the image hereAfter recharging:

enter the description of the image here

Thank you for your answers and sorry for my messy English and my messy explanation.