1

I wanted to ask for some advice on where can I update my infowindow in case if there are no news for the area. I will show you what I have already tried.

function showInfo(marker, content)
{
// start div
var div = "<div id='info'>";
if(typeof(content) === "undefined")
{
    // http://www.ajaxload.info/
    div += "<img alt='loading' src='img/ajax-loader.gif'/>";
}

else
{
    if(jQuery.isEmptyObject(content))
    {
        div+="No news today!!";
    }else{
        div += content;
    }

}

// end div
div += "</div>";

// set info window's content
info.setContent(div);

// open info window (if not already open)
info.open(map, marker);
}

1 Answer 1

1

Let's look at this: if(jQuery.isEmptyObject(content))

What is inside the variable content when you pass it to the showInfo() function via the addMarker() function?

It's always a long string full of html code, right? Even if the response from $.getJSON inside addMarker() was an empty.

So this if(jQuery.isEmptyObject(content)) part won't ever work as you intend, because content is not a JavaScript empty object, but just a long string always full of html.

Look at jQuery.isEmptyObject() documentation: enter image description here

Now try to call $.isPlainObject on content to see what's the output. I'm sure it won't return true.

Maybe you should check if $.getJSON returned any links inside the addMarker() function, and if there are no links you set content to be what you want to be before you pass it to showInfo().

1
  • I am going to check this tomorrow after work, thank you for advice.
    – Kamil Kug
    Commented Oct 26, 2016 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .