여기서 무엇을 하려는지는 JavaScript 변수를 PHP 함수로 보내는 것입니다. 내가 개발중인 것은 특정 경도/위도에 도달하면 체크인 할 수있는 jQuery Mobile App입니다. 하지만 위도/위도를 PHP 함수에 보내는 데 문제가 있습니다. 내가 데이터베이스에 저장 한 경도/위도와 비교를 할 것이므로 Im을 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 측을 게시하시기 바랍니다 (PARAMS의 꺼내는데 파트)를 보여> 을 그리고 wellformed JSON합니다 –
를 {경도 "위도": 위도, "LNG를"} @frank_neff : JSON이 아닌 객체 리터럴입니다. 따옴표가 필요 없습니다. AJAX 라이브러리는 소스 코드에 따옴표가 있는지 여부와 관계없이 객체를 올바른 형식의 JSON으로 직렬화합니다. – RoToRa