javascript - Send Lat and Long details via Ajax -


i trying write code once button pressed sends lat , long coordinates via ajax test.php file. problem having not seem call test.php file.

<button onclick="getlocation()">join me</button>                    <p id="demo"></p>   <script>     var x = document.getelementbyid("demo");        function getlocation() {          if (navigator.geolocation) {           navigator.geolocation.getcurrentposition(showposition);       } else {            x.innerhtml = "geolocation not supported browser.";           }       }      function redirecttoposition(position) {       // ...       $.ajax({         type: "post",         url: "http://www.domain.co.uk/test.php",         data:   "lat="+position.coords.latitude+"&long="+position.coords.longitude,        });    } 

below content of test.php file,

$lat=(isset($_post['lat']))?$_post['lat']:''; $long=(isset($_post['long']))?$_post['long']:'';  $to      = 'lee@recruit-technology.co.uk'; $subject = 'the subject'; $message = "$lat; $long;"; $headers = 'from: webmaster@example.com' . "\r\n" . 'reply-to: webmaster@example.com' . "\r\n" . 'x-mailer: php/' . phpversion();  mail($to, $subject, $message, $headers); 

here. i've set fiddle you. looks may referencing wrong method name (getcurrentposition vs redirecttoposition). if that's not case, looks never call redirecttoposition(), , that's why code block never executes.

try editing fiddle, changing out actual domain uri.

    var x = document.getelementbyid("demo");    function getlocation() {      if (navigator.geolocation) {       navigator.geolocation.getcurrentposition(showposition);   } else {        x.innerhtml = "geolocation not supported browser.";       }   }  function getcurrentposition(position) {   // ...   $.ajax({     type: "post",     url: "http://www.domain.co.uk/test.php", // -> actual domain here.     data:   "lat="+position.coords.latitude+"&long="+position.coords.longitude    }); } 

http://jsfiddle.net/tcysvkfz/

at rate, method executes ajax request never invoked in example, , that's why test.php never hit.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -