javascript - ajax request cordova geolocation -
hi new ajax , trying make ajax request within geolocation api in cordova. longitude , latitude user should sended setlatcookie.php doesnt work. mistake? on device no error code showing white screen. app run browser shell if heplful.
<script type="text/javascript"> // wait device api libraries load // document.addeventlistener("deviceready", ondeviceready, false); // device apis available // function ondeviceready() { navigator.geolocation.getcurrentposition(onsuccess, onerror); } // onsuccess geolocation // function onsuccess(position) { latitude = position.coords.latitude; longitude = position.coords.longitude; xmlhttp.onreadystatechange=function() { } xmlhttp.open("get","setlatcookie.php?la="+latitude,true); xmlhttp.send(); xmlhttp.open("get","setlatcookie.php?lo="+longitude,true); xmlhttp.send(); } } // onerror callback receives positionerror object // function onerror(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } </script> setlatcookie.php :
<?php $latitude = $_get["la"]; $longitude = $_get["lo"]; $t = time() + 60 * 60 * 24 * 1000; setcookie("latitude", $latitude, $t); setcookie("longitude", $longitude, $t); ?>
Comments
Post a Comment