0

I've almost finished pset8 Mashup but I'm a bit confused as to whether the news articles in the information windows are supposed to open when I click on a news article. I have added markers to my map for locations and when clicked, an infowindow opens with a list of bulleted news articles but I am unable to open any of the articles when I click on a news article link. Should I be able to open any news article when I click on its link in a given infowindow? Any clarification about this would be appreciated.

// display infowindow when clicked

    google.maps.event.addListener(marker, 'click', function() {

    showInfo(marker);

    // gets JSON for the news articles

    $.getJSON("articles.php", {geo: place.place_name})
    .done(function(data, textStatus, jqXHR )
    {

    if (data.length === 0)
    {
        showInfo(marker, "No news today :(");
    }

    else
        {
        var content = "<ul>";

        // template for ul

        var template = _.template("<li><a href'<%- link %>' target='_blank'>'<%- title %>'</a></li>");

        // iterate through the news

        for (var i = 0; i < data.length; i++)

        content+= template({link: data[i].link, title: data[i].title});

        // close list

        content+= "</ul>";

        // show infowindow

        showInfo(marker, content);
        }

    })

    .fail(function(jqXHR, textStatus, errorThrown) {

    // log error to browser's console

    console.log(errorThrown.toString());


    });

});

}
8
  • Yes, you should Commented Dec 10, 2016 at 18:23
  • If I can't open any of the news articles then what is likely to be the problem? Commented Dec 11, 2016 at 12:37
  • That would be difficult to answer without seeing your code, right? Commented Dec 11, 2016 at 12:37
  • I agree. I'm sure that the problem lies in my scripts.js file Commented Dec 11, 2016 at 12:46
  • Couldn't you just edit your original post? Commented Dec 11, 2016 at 13:11

1 Answer 1

0

You're missing an equal sign = after href here:

var template = _.template("<li><a href'<%- link %>' target='_blank'>'<%- title %>'</a></li>");

should be:

var template = _.template("<li><a href='<%- link %>' target='_blank'>'<%- title %>'</a></li>");

If this solves your problem, please click the gray check to the left of the page to accept this answer and close this question.

2
  • Thanks so much. I can now open any news article. Commented Dec 11, 2016 at 13:35
  • Great! You can delete all those comments with code up there later, then! Good luck on the next task. Commented Dec 11, 2016 at 13:36

You must log in to answer this question.

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