- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hey all.
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!
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.
thanks alot thomas. That did the trick. Figured out it was returning a length of 1.