Right now my code looks like this:
<script typ开发者_Python百科e="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?
$.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.
精彩评论