My links for non-Onion articles are displaying just fine in infoWindows attached to markers, but even though the Onion aricles are fetched correctly through ajax, they are not being displayed in my infoWindows (the infoWindows that should have Onion articles are instead tiny and empty). Does anyone have an idea as to why this is happenning? Would really appreciate help :) My code is as follows:

var contentString = "";
$.getJSON(Flask.url_for("articles"), {geo: place['postal_code']})
.done(function(data, textStatus, jqXHR){
    contentString = "<ul>";
    for(var i = 0; i < data.length; i++){
        var obj = data[i];
        contentString = contentString + "<li><a href=\"" + obj.link + "\">" + obj.title + "</a></li>";
    contentString = contentString + "</ul>";

var infoWindow = new google.maps.InfoWindow({});

marker.addListener('click', function() {
    infoWindow.open(map, marker)
  • If articles returns a list of dict objects as created by helpers.lookup, this function will process Onion articles the same as any other. I think that indicates a problem in the articles function. BTW what is the datatype of postal_code in the database? It should be TEXT, esp. because that will not drop leading 0's on US zip codes, and lookup will give better results. – DinoCoderSaurus Jul 27 '17 at 19:21
  • I'm fairly sure there isn't a problem with the articles function. When I go to ide50-myusername.cs50.io/articles?geo=[postcode], the correct JSON object is returned (for both, Onion and non-Onion articles). The problem only appears when I try to display the Onion articles in an infoWindow. And postal_code is TEXT as well. This is why I'm really confused as to what I'm doing wrong :( – mathmagician Jul 28 '17 at 10:52
  • UPDATE: Now that I've done even more testing, I realised that even some places which return JSON objects with articles from Google News do not display said articles in infoWindows. After refreshing the page and looking for a place which previously had an empty infoWindow again, I sometimes find that articles appear. What's happenning? – mathmagician Jul 28 '17 at 11:01

In lieu of troubleshooting your code, a suggestion: Use the tools!

From the spec:


This function opens the info window at a particular marker with particular content (i.e., HTML). Though if only one argument is supplied (marker), showInfo simply displays a spinning icon (which is just an animated GIF). Notice, though, how this function is creating a string of HTML dynamically, thereafter passing it to setContent. Perhaps keep that technique in mind elsewhere!

This is "elsewhere". Instead of creating 10 new infoWindows, why not use the one already "built-in"?

You can make your click listener function as simple as showInfo(this, contentString). (You'll need to use this instead of marker so that it shows the infoWindow on the marker that has been clicked instead of the last value of marker).

There are missing ; in the current listener function (which may or may not be causing these specific problems).

You must log in to answer this question.

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