The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other test for empty response ajax

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #34589

    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:

    url: getNextPage(),//returns url (, etc.)
    dataType: ‘html’,
    success: function(data) {
    $(‘a[rel=”lightbox”]’).colorbox({transition: “fade”}); //adds lightbox to new lis
    if(data.length == 0) {
    }//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 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.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Other’ is closed to new topics and replies.