im trying to store an ajax respone to the Post php variable and then echo it on the same page, but sadly, it returns "Notice: Undefined index"
I think its something with the success part of the ajax.Could you help me correct it?
Thanks in advance:)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<form action="" method="post">
<input type="submit" name="ido" value="Click" /></td>
</form>
<script>
var x=document.getElementById("log");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="GPS szolgáltatás nem müködik ezen a böngészőn, kérlek értesítsd a rendszergazdát!";}
}
function showPosition(position)
{
navigator.geolocation.getCurrentPosition(showPosition);
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.ajax({
url: "test.php",
type: 'POST', //I want a type as POST
data: {'name' : latitude },
success: function(response) {
alert(response);
}
});
}
</script>
<?php
if(isset($_POST["ido"])){
echo "<script>getLocation();</script>";
$name=$_POST["name"];
print_r($_POST);
}
?>
</html>