I've gone as far as I can with the below script, but I can't for the life of me work out why the page id is not being sent to the PHP script.
Currently I'm grabbing the "index.php?id=12" with a PHP _GET command then inserting that into a Javascript variable. I set up a 2nd variable that includes that, as well as a string for latitude and longitude. When I test that the string is created via an alert, the string looks exactly like it should.
Inside my PHP script, I only every get the longitude and latitude data, but never the id data. Having read a number of other threads on here I believe the Ajax is expecting an object and that the string is unexpected. Unfortunately I do not know how to rectify this.
My Javascript is as follows:
function GeoSuccess(position) {
var id = <?php echo $id ?>;
var dataString = '?id='+id+'&action=geolocation&latitude='+position.coords.latitude+'&longitude='+position.coords.longitude;
$.ajax({
url: 'search.php',
type: 'GET',
data: dataString,
success: function (msg) {
$('div#search-results').html(msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Error submitting request.');
}
});
}