Thursday, 29 August 2013

Why does my function sometimes not execute the document.body.innerHTML command?

Why does my function sometimes not execute the document.body.innerHTML
command?

I've made a function to output data from Google Maps using the Google API.
The function is called to output from an array of places.
The problem is that sometimes it won't output the last
document.body.innerHTML part which outputs the place's URL. If I remove
the for loop which outputs the place's review aspects then the URL is
always shown.
function printme(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
document.body.innerHTML += ('<br />'+ place.name + ' R: '+ place.rating);
for (var i = 0, reviews; reviews = place.reviews[i]; i++) {
for (var x = 0, aspectr; aspectr = reviews.aspects[x]; x++) {
document.body.innerHTML += ('<br />'+'Aspect: ' + aspectr.type + ' '
+ aspectr.rating);
}
}
document.body.innerHTML += ('<br />'+ '<a href =
'+place.url+'>'+place.url+'</a>'+'<br />');
}
else {
alert(status);
}
}
I can't get my head around why that is.

No comments:

Post a Comment