PHP & jQuery "$.post" are making troubles. I'm posting a few variables to a PHP-File.
The jQuery is:
navigator.geolocation.getCurrentPosition(saveGeoLocation);
function saveGeoLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.post("__g.php", {
latitude: latitude,
longitude: longitude
}).done(function(data) {
console.log("Data Loaded: " + data);
});
}
The PHP is:
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
echo "Position output: " . $latitude . $longitude;
The console is showing the echo correctly with all the information sent via jQuery. However on the page itself, the PHP-echo is just echoing the content inside the quotation marks but not the variables content.
The PHP is in a single file but imported to a bigger file via include().
(This is a reduced example, there could be a typo.)
Thanks for your wisdom!
----------EDIT--------:
My problem might be based on a rookie mistake. Is it possible to include a php file AND at the same time send data to it so that it outputs the data in the place you want it to? Like:
<somehtml>
<somejquery> *--> is retrieving Geolocation-coordinates and posting long/lat to "__g.php"*
<?php
<somephp>
include("__g.php"); *--> is echoing the full API-url containing the long/lat values from the jQuery-post*
<someforeach> *--> for the received API-json*
?>