即時試圖存儲一個ajax輸入反應向早報PHP變量,然後呼應它在同一頁上,但遺憾的是,它返回的結果「公告:未定義指數」不能看到一個Ajax調用
我認爲它阿賈克斯成功的一部分。你能幫我糾正嗎?
感謝提前:)
<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>
你得到的'alert'? – thefourtheye
確實,我沒有看到'name'發送到帖子。未定義的索引意味着數組找不到您要查找的值。 – Colandus
看到這個帖子:http://stackoverflow.com/questions/8300068/undefined-index-errors-accessing-post –