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:
And so, here is my script:

jQuery(function($) {
var refresh = function(){

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

I have included it in my functions.php

    get_template_directory_uri() . '/js/script.js',
    array( 'jquery' ),

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: -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.

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.