I am trying to test for an empty ajax response so that I can hide a loading gif when the server returns no data.
I have this:
$.ajax({ url: getNextPage(),//returns url (http://mysite.com?start=15, etc.) dataType: 'html', success: function(data) { $('#catalog-items').append(data); $('a[rel="lightbox"]').colorbox({transition: "fade"}); //adds lightbox to new lis if(data.length == 0) { $('#next-page-spinner').hide(); }//supposed to hide the loader } });
I thought that giving data a type of 'html', the server would return an empty string when the response contained no data (i.e., when the url is mysite.com?start=60 and there are only 50 items in the db), thus data.length == 0 would be true and the spinner would be hidden. I have verified that no Content is being returned. Any thoughts?
Try adding an alert or console.log to verify if data.length really is zero. If it is, then the problem is with the line responsible for hiding the loading image. If it isn't, then you need to find out what is really being returned.
I am trying to test for an empty ajax response so that I can hide a loading gif when the server returns no data.
I have this:
$.ajax({
url: getNextPage(),//returns url (http://mysite.com?start=15, etc.)
dataType: 'html',
success: function(data) {
$('#catalog-items').append(data);
$('a[rel="lightbox"]').colorbox({transition: "fade"}); //adds lightbox to new lis
if(data.length == 0) {
$('#next-page-spinner').hide();
}//supposed to hide the loader
}
});
I thought that giving data a type of 'html', the server would return an empty string when the response contained no data (i.e., when the url is mysite.com?start=60 and there are only 50 items in the db), thus data.length == 0 would be true and the spinner would be hidden. I have verified that no Content is being returned. Any thoughts?
Thanks alot!