[OpenLayers-Users] help with passing a var from OL to PHP

Jason.Woolard at noaa.gov Jason.Woolard at noaa.gov
Mon Nov 7 17:01:05 EST 2011


hi,

I have a simple base map and I'm clicking the map to retrieve the lat/lons that will be fed into a url to retrieve a json file. I'm having trouble returning the url I want to send via PHP. I'm almost certain the problem is in the OpenLayers.Request but the docs and examples haven't helped me through this one. Can anyone see what my problem is here? 

Thanks in advance!

Relevant parts of code below:
.....
map.events.register("click", map, function(e) {
      var position = map.getLonLatFromPixel(e.xy);
      position.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));			  
      var mouselat = position.lat;
      var mouselon = position.lon;
      var geturl = 'http://locationofthejson.com/'+mouselat+','+mouselon+'.json';
      // console.log(geturl);  This prints the url ok!


       var request = OpenLayers.Request.POST({
	                       url: "http://localhost:8888/mypage.php",
			    	data: geturl,
				headers: {
					 "Content-Type": "text/plain"
				},
				success: function(request) {
						alert(request.responseText);
				}
			  });
          });

 <?php
	
	if (isset($_GET['geturl'])) { $get_url = $_GET['geturl'];}
        $json_string = file_get_contents($get_url);
	$parsed_json = json_decode($json_string);

        echo 'console.log("'.$get_url.'");';  // Nothing returned here!
?>


More information about the Users mailing list