SF23103 Posted February 11, 2015 Share Posted February 11, 2015 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> Quote Link to comment https://forums.phpfreaks.com/topic/294537-only-getting-first-piece-of-data/ Share on other sites More sharing options...
CroNiX Posted February 11, 2015 Share Posted February 11, 2015 I believe infowindow.setContent() only accepts one parameter - the entire HTML to replace the content of the infowindow with. There is also infowindow.setTitle(title) to update the title. Quote Link to comment https://forums.phpfreaks.com/topic/294537-only-getting-first-piece-of-data/#findComment-1505476 Share on other sites More sharing options...
SF23103 Posted February 12, 2015 Author Share Posted February 12, 2015 Dang it! Ok. Each info window.setContent() is going to have some html with specific variables corresponding to the marker. Maybe I can just insert the php variables in there in the html. I'll play around with it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/294537-only-getting-first-piece-of-data/#findComment-1505480 Share on other sites More sharing options...
Solution CroNiX Posted February 12, 2015 Solution Share Posted February 12, 2015 (edited) 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 February 12, 2015 by CroNiX 1 Quote Link to comment https://forums.phpfreaks.com/topic/294537-only-getting-first-piece-of-data/#findComment-1505483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.