samedi 27 juin 2015

Auto Refresh a div using jQuery

I need to auto refresh a specific div, i tried the following code but it make a lot of requests to the server instead of one every 5 seconds.

<script type="text/javascript">
        $(document).ready(function() {
            refresh();
        });

        function refresh() {
            $.get('site', function(result) {
                $('#div').html(result);
            });
            setTimeout('refresh()', 5000);
        }

    </script>

Aucun commentaire:

Enregistrer un commentaire