Jump to content

Only getting first piece of data


SF23103

Recommended Posts

On the below line of code, I am getting the output for the first item only (data.title).  If I put data.url first, I only get that output, etc.  I'm new to javascript and may be missing something.  Should I not be separating them with ,'s, or is there another way to do this? 

infowindow.setContent(data.title , data.url , "this is a test");

This is part of a larger google maps app that plots points on a map.  Using markers, the line above opens an info window displaying some data about the point.  It's working great, except its not displaying all the data as described above.

    <script type="text/javascript">
      $(document).ready(function() {
        $.getJSON("database-to-json.php", function(json1) {
		  $.each(json1, function(key, data) {
            var latLng = new google.maps.LatLng(data.lat, data.lng); 

            var marker = new google.maps.Marker({
                position: latLng,
                title: data.title,
		url: data.url
            });
			
    marker.setMap(map);
   google.maps.event.addListener(marker, 'click', function() {
   infowindow.setContent(data.test , data.title);
   infowindow.open(map,marker);		
    });
			
          });
        });
      });
    </script>
Link to comment
https://forums.phpfreaks.com/topic/294537-only-getting-first-piece-of-data/
Share on other sites

Yes, just have php parse it and send the final HTML back in the ajax request instead of individual parts. Well, you'd have 2 parts with the html and the title.

 

something like

[
  {html: '<strong>The HTML</strong>', title: 'The Title'},
  {html: '<strong>Different HTML</strong>', title: 'Another Title'}
]

Then in the loop

infowindow.setContent(data.html);
infowindow.setTitle(data.title);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.