Jump to content

Only getting first piece of data


SF23103
Go to solution Solved by CroNiX,

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
Share on other sites

  • Solution

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);
Edited by CroNiX
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.