title: Jquery ajax Post variables to php
body: <p>my ajax.php script</p>
  
  <pre><code>&lt;?php
  $lat =$_POST['lat'];
  $lon = $_POST['lon'];
  echo $lat;
  echo $lon;
  ?&gt;
  </code></pre>
  
  <p>And my new.html page</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;&lt;head&gt;&lt;script src="jquery-1.12.0.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;p&gt;Click the button to get your coordinates.&lt;/p&gt;
  &lt;input type="text" name="metin"/&gt;&lt;br/&gt;
  &lt;button onclick="getLocation()"&gt;Try It&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  
  
  &lt;p id="demo1"&gt;&lt;/p&gt;
  &lt;script&gt;
  
  var x = document.getElementById("demo");
  var y = document.getElementById("demo1");
  
  function getLocation() {
      if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(showPosition);
      } else { 
          x.innerHTML = "Geolocation is not supported by this browser.";
      }
  }
  function showPosition(position) {
      x.innerHTML = "Latitude: " + position.coords.latitude + "&lt;br&gt;Longitude: " + position.coords.longitude;
      var lon= position.coords.longitude;
      var lat= position.coords.longitude;
      y.innerHTML=lon;
      x.innerHTML=lat;
      $.ajax({
              type: 'POST',
              url: 'ajax.php',
              data:  { lat:lat, lon:lon}
               success: function(result) {
                  $('#sonuc').html(result);
              },
              error: function() {
                  alert('Some error found. Please try again!');
              }
          });
      }
  }
  
  &lt;/script&gt;
  
  &lt;p id="sonuc"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Firstly i know there is unused codes. But İ'm gonna use this blocks.
  İt's not give me any response. İt's have to work successfuly.
  But it's not give me lat and lon varibles in my php page.
  İf there is another way to send variables to php page i can try.</p>