Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to pass a JS variable onto PHP and use it there
    primarykey
    data
    text
    <p>I want to pass variables to PHP from JavaScript. I've read about not being able to do this without a AJAX call, or putting it in the URL in JavaScript and then working with <code>$_GET</code>. The problem is that my variables are created on initialize (on window load) so if I try <code>$_GET</code> I get stuck in an infinite loop.</p> <p>The variables are <code>lati</code> and <code>longi</code>.</p> <p>Here is my JavaScript (without the AJAX call, since that created an infinite loop etc..):</p> <pre><code>var map; function initialize() { var mapOptions = { zoom: 12, streetViewControl: false, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions); // Try HTML5 geolocation if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); var lati = position.coords.latitude; var longi = position.coords.longitude; map.setCenter(pos); }, function() { handleNoGeolocation(true); }); } else { // Browser doesn't support Geolocation handleNoGeolocation(false); } var length = locationsArray.length, element=null; for (var i = 0; i &lt;length; i++) { element= locationsArray[i]; var element1 = element.split(";"); var posi = new google.maps.LatLng(element1[0],element1[1]); var marker = new google.maps.Marker({ position: posi, map: map, icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&amp;chld='+i+'|e74c3c|333333', url: 'index.php?id='+i+'#eventDetails' }); google.maps.event.addListener(marker, 'click', function() { window.location.href = this.url; }); } } google.maps.event.addDomListener(window, 'load', initialize); </code></pre> <p>The PHP where I want to use the variable:</p> <pre><code>$url="http://build.uitdatabank.be/api/events/search?key=AEBA59E1-F80E-4EE2-AE7E-CEDD6A589CA9&amp;latlng=".$lati.";".$longi."!10km&amp;format=json"; $events= json_decode(file_get_contents($url)); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload