Update timed image using AJAX

1

I have this function:

 if ($files_count == 0) {
    ?>
    <img src="img/upload.gif">
    <?php
 }

And I needed this refreshed every 5 seconds without giving refresh on the page. I have already tried several AJAX functions and I can not. How do I resolve this?

    
asked by anonymous 08.07.2014 / 18:03

1 answer

1

Solution!

HTML:

<div class="container"></div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">

SCRIPT:

setInterval(function () {
    check_files();
}, 5000);

function check_files() {
    $.ajax({
        url: 'path/to/php/file.php',
        type: 'GET',
        cache: false,
        data: {},
        success: function (resp) {
            if (resp == 0) {
                $('.container').html('<img src="img/upload.gif" />');
            } else {
                /// mais alguma coisa
            }
        }
    });
}
    
09.07.2014 / 14:24