2

Here at the last pset, I run into the first time I had to post a question (instead of just browsing other questions' answers).

I have clickable markers, but content never fills in. When a marker is clicked, an empty infoWindow appears.

marker.addListener('click', function(){

    var content = "";

    // pull articles
    var parameters = {geo: place.postal_code}

    $.getJSON("articles.php", parameters)
    .done(function(data, textStatus, jqXHR) {
        // if there are any articles
        // add items in data to list
        // else, set content default message
    })
    .fail(function(jqXHR, textStatus, errorThrown) {
        // log error to browser's console
        console.log(errorThrown.toString());
    });

    showInfo(marker, content);
});

Am I failing to return content so showInfo can access it?

I've tried the recommendations from $.getJSON and $.ajax not working and $.getJSON in PSET8 mashup's addMarker function in scripts.js and addMarker pset8 mashup JSON not returning data, and none of them worked.

Thanks.

8
  • Could you try, instead of content += "<li><a href=" + data[i].link + " target=\"_blank\">" + data[i].title + "</a></li>"; to use content += "<li><a href= \"" + data[i].link + "\" target=\"_blank\">" + data[i].title + "</a></li>"; and let me know?
    – ChrisG
    Sep 11, 2015 at 21:03
  • That doesn't solve the root problem (still have an empty infoWindow), although I think you've saved me from a future issue. I think the $.getJSON .done function is not executing at all, because however I set var content = at the very top is what appears in the infoWindow. So expecting .fail, I looked at the console for an error message, but nothing shows up there either. @ChrisG Sep 12, 2015 at 12:04
  • Could you also change .done(function(data, textStatus, jqXHR) to just .done(function(data)?
    – ChrisG
    Sep 12, 2015 at 12:42
  • With that change, still an empty infoWindow. @ChrisG Sep 12, 2015 at 19:38
  • Can you try to add window.alert(content); inside the if condition of .done part? Also one add a window.alert("Got inside done!"); write inside the .done part to see if it really executes.
    – ChrisG
    Sep 12, 2015 at 20:02

1 Answer 1

2

I thought the problem was in the $.getJSON part, but instead, it was putting showInfo(marker, content); OUTSIDE $.getJSON.done. As @ChrisG helped me discover (see comments above), it returns at the end of .done, so content had not been accessible to showInfo.

A few window.alerts demonstrated that $.getJSON was working properly, so from there, it wasn't hard to move the last puzzle piece - showInfo(marker, content); INSIDE $.getJSON.done.

Thanks, ChrisG!

You must log in to answer this question.

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