Jquery ajax script doesn't change div content if ajax returns nothing?
I am wondering how i can change this jQuery Ajax scri开发者_开发知识库pt so it doesn't change the div content if the Ajax returns nothing? I'm pretty new to jQuery & JavaScript sorry. Thanks :)
Source code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('record_count.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
<body>
<div id="load_tweets"> </div>
</body>
</script>
Instead of using the .load()
function:
$('#load_tweets').load('record_count.php').fadeIn("slow");
Try $.ajax()
:
$.ajax({
url: 'record_count.php',
type: 'GET',
success: function(result) {
if (result != null && result != '') {
$('#load_tweets').html(result).fadeIn('slow');
}
}
});
Try to use the ajax jquery version to get more control on your request. You can see the response data and see if it has data.
var auto_refresh = setInterval(function(){
$.ajax({
url: "record_count.php",
success: function(data){
if(jQuery.trim(data) != ""){
$('#load_tweets').html(data);
}
},
dataType: 'html'
});
}, 10000);
精彩评论