in my xhtml page i have a field where the user put an adresse and when he click on the buton then gps coordinates are displayed in too input text. i want to add ajax to insert these too values into a database. i use this script in my xhtml page.
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
addr, latitude, longitude;
function geolocalise(){
addr = document.getElementById('adresse').value;
geocoder.geocode( { 'address': addr}, function(results, status) {
// Si g?oloc OK
if (status == google.maps.GeocoderStatus.OK) {
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
document.getElementById('lat').value = latitude;
document.getElementById('lng').value = longitude;
document.getElementById('aa').innerHTML=longitude;
var sendAjax = $.ajax({
type: "POST",
url: 'http://10.0.2.2/xx/insert-in-bdd.php',
data: 'lat='+latitude+'&lng='+longitude+'&adr='+addr,
success: handleResponse
});
}
function handleResponse(){
$('#answer').get(0).innerHTML = sendAjax.responseText;
}
});
}
</script>
i tested milion times..nothing seems to work. The url
url: 'http://10.0.2.2/xx/insert-in-bdd.php',
is pointing to my localhost, the php file is in C:/Wamp/xx
my php file is
<?php
header('Content-type: text/html; charset=ISO-8859-1');
if(isset($_POST['lat']) && isset($_POST['lng'])){
$lat = addslashes($_POST['lat']);
$lng = addslashes($_POST['lng']);
$adr = addslashes($_POST['adr']);
$db = mysql_connect("localhost", "root", "");
$select = mysql_select_db(project, $db);
mysql_query('INSERT INTO test (lat,lng,adresse)
VALUES('$lat')');
echo 'Vos coordonnées ont bien été insérées en base de données.';
}else
echo 'Problème rencontré dans les valeurs passées en paramètres';
?>
note: I create the database project and the table test
im caling the geolocalise here:
<input type="text" id="adresse"
value="saisissez votre adresse"
style="width: 291px; border: 1px solid #ccc;" /> <input
type="button" onclick="geolocalise()" value="geoooo"
style="border: 1px solid #ccc; padding: 1px; cursor: pointer;" />
<br />
<br />
Latitude : <input type="text" id="lat" value=""
style="border: 1px solid #ccc;" />
longitude <input
type="text" id="lng" value="" style="border: 1px solid #ccc;" />
<div id="answer">Réponse</div>
why is not working Thank you for helping me