我已經瀏覽了幾個類似的線程 - 但無法確切地知道我要出錯的地方。 我正在使用AJAX & PHP創建一個應用程序的用戶lng & PHP。我知道AJAX & PHP的工作原理是將所有內容(甚至是虛擬的數據)保存到我的數據庫表中。 我一直在玩幾個小時的變量,迄今爲止我得到的最好結果是在數據庫中插入了一個「0」值。使用AJAX將地理位置數據發佈到PHP
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
getCurrentLocation();
}
function onError(message) {
navigator.notification.alert(message, "", "Error");
}
function getCurrentLocation() {
navigator.geolocation.getCurrentPosition(locationSuccess, onError);
}
function locationSuccess(position) {
lat = document.getElementById("latSpan");
lon = document.getElementById("latSpan");
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
//recording function
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}
var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
function ajaxFunction() {
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
xmlhttp.open("POST","http://www.lauracrane.co.uk/app/rec/location.php",true); //
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("latitude=" + latitude + "&longitude=" + longitude);
}
}
function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById("message").innerHTML=xmlhttp.responseText;
}
else {
alert("Error during AJAX call. Please try again");
}
}}'
我想知道是否有人能看到爲什麼它不緯度& LNG的值傳遞給AJAX功能。
任何幫助,將不勝感激。 :)
勞拉
你檢查是否在PHP端接收的數據?因爲那應該看起來不錯。如果你使用INT來保存經度和緯度,那麼問題可能出現在數據庫端 – cleanunicorn
嗨,它是VARCHAR--只是檢查一下,但感謝你的幫助。 :) – LCrane86