My infoWindows are working fine when there is text to be displayed in them, but I'm struggling with empty infoWindows. The code I tried to use to implement the empty window functionality is below:

$.getJSON(Flask.url_for("articles"), {geo: place['postal_code']})
.done(function(data, textStatus, jqXHR){
    if(data.length == 0){
        // the console.log would obviously be replaced with adequate code
    // code for when there are news items to display

I'm using the data.length == 0 condition to check if the data returned through JSON is empty. However, even when there are no news items to display the condition fails to execute. This is confusing me because when I change it to data.length > 0, the console.log statement always executes (even when there are no news articles!).

How would I go about fixing this? Why is the data always longer than 0, even when there are no articles to display? I've been at this single line for two days, so I will really appreciate help :)

  • What does articles return? Suspect it's a list of a list of dicts, which would cause this problem. Jul 27, 2017 at 13:13
  • Oh, I see where my mistake is. If there are no local articles for a place, articles returns a list of dicts containing articles from The Onion. Hence why data never comes back as empty! Jul 27, 2017 at 13:48


You must log in to answer this question.

Browse other questions tagged .