即時嘗試在這裏做的是發送一個JavaScript變量到PHP函數。我正在開發的是一個jQuery Mobile應用程序,您可以在達到特定的經度/緯度時進行檢查。但是我在向PHP函數發送經度/緯度時遇到了問題。我發送它到一個PHP函數,因爲我要做一個比較,我已經存儲在我的數據庫中的經度/緯度。發送JavaScript變量到PHP
這是我的代碼。
function testResults() {
if(navigator.geolocation) {
//Get the current position
navigator.geolocation.getCurrentPosition(function(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.write("lat", latitude);
document.write('<br /><br />');
document.write("long", longitude);
});
} else {
alert("Sorry... your browser does not support the HTML5 GeoLocation API");
}
//////////// Here I tried with jQuery/Ajax. I know that it's wrong.
//////////// Im putting it here so that it maybe clarifies what Im
//////////// trying to do.
$.post("checkLocation.php", {
lat : latitude,
longi : longitude
}, function(data) {
alert("Data Loaded: " + data);
});
////////////////////////////////////////////////////////////////////
}
testResults();
我該如何解決這個問題?我用JSON嘗試過,但我沒有得到它的工作。任何幫助將不勝感激。
顯示你的PHP代碼 – Distdev
請發表您的應用程序的PHP端(使用參數的檢索部分)> 並作出簡潔(wellformed)JSON: {「LAT」:緯度,「LNG」:經度} –
@frank_neff:這是一個對象字面值,而不是JSON。沒有必要在那裏報價。 AJAX庫將對象序列化爲格式良好的JSON,完全獨立於源代碼是否帶引號。 – RoToRa