tags:

views:

35

answers:

1

Right now my code looks like this:

<script type="text/javascript">
    $(document).ready(function() {
        $.ajaxSetup({
            cache: false
        });

        var loadUrl = "<?php echo site_url("admin/get_uploads"); ?>";  

        $("#result").load(loadUrl);

        var refreshId = setInterval(function() {
            $("#result").load(loadUrl);
        }, 1000);
    });
</script>

The problem is that the gets refreshed every second, therefore if I have something selected within that div, after a second, the select resets to non-selected.

Is there a way to have jQuery to only bring in new data if it's available and not refresh the every second?

+4  A: 
$.get(loadUrl,function(result){
    if(result !=  $("#result").html())
    {
        $("#result").html(result);
    }
});

A better solution would be to use a comet type approach, long polling is fairly easy to implement.

Paul Creasey
+1. You beat me to it. :)
casablanca
Awesome. Thanks!
dallen