2012-01-25 3 views
1

몇 가지 유사한 스레드를 살펴 보았지만 잘못된 부분을 정확히 볼 수 없습니다. AJAX & PHP를 사용하여 작성중인 앱에 & 명의 사용자를 저장하고 있습니다. 나는 AJAX & PHP가 내 데이터베이스 테이블에 모든 것을 저장하기 때문에 (심지어 거짓 더미 & lng 값) 저장된다는 것을 알고있다. 저는 몇 시간 동안 변수를 가지고 놀았으며 지금까지 가지고있는 최선의 결과는 데이터베이스에 '0'값이 삽입 된 것입니다. 는 AJAX 기능에 위도 & LNG의 값을 전달하지 왜 사람이 볼 수있는 경우AJAX를 사용하여 PHP에 Geolocation 데이터 게시

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"); 
} 
}}' 

궁금 해서요.

도움을 주시면 감사하겠습니다. :)

로라

+0

을 사용하는 것이 좋습니다까요? 왜냐하면 그건 괜찮아 보일테니까. 위도와 경도를 저장하기 위해 INT를 사용하는 경우 문제가 데이터베이스 측에있을 수 있습니다. – cleanunicorn

+0

안녕하세요, VARCHAR입니다. - 그냥 확인했지만 도움을 주셔서 감사합니다. :) – LCrane86

답변

0

어쩌면 우리가 모든 코드를 볼 수 있지만 위도와 경도과 같은 기능이 locationSuccess로 범위가 있습니다. 그래서 당신은 ajaxFunction에서 그것들에 접근하려고 시도 할 때 기본값을 얻을 것입니다.

또한 getXMLObject fun를 모두 수행 할 필요는 없습니다.

var xmlhttp = new XMLHttpRequest(); 

그리고 마지막으로 당신은 아마 파일의 떨어져이 실행되기 때문에 : // 프로토콜을 사용하면 0의 상태 코드를 찾을 것입니다 안드로이드, iOS 및 블랙 베리와 같은 웹킷 브라우저에 당신은 할 필요가 이 경우 200과 유사합니다.

function handleServerResponse() { 
    if (xmlhttp.readyState == 4) { 
     if(xmlhttp.status == 200 || xmlhttp.status == 0) { 
      document.getElementById("message").innerHTML=xmlhttp.responseText; 
     } 
    } 
    // etc. 
} 
0

jQuery ajax 호출을 사용하지 않는 이유는 무엇입니까? 귀하의 코드는 IE6 용으로 마크 업되었습니다 ...이 때문에 phonegap 태그로 나는 당신이 일을의 새로운 방법을 사용하여 액세스 할 수 있다고 가정합니다.

난 당신이 PHP 측에서 수신 된 데이터를 확인 했 jQuery를 아약스 ..

function ajaxFunction() { 
$.ajax({ 
    url:'http://www.lauracrane.co.uk/app/rec/location.php', 
    type:'POST', 
    data:'lat='+lat+'&long='+long, 
    success:function(d){ 
    console.log(d); 
    }, 
    error(w,t,f){ 
    console.log(w+' '+t+' '+f); 
    } 
}); 
} 
관련 문제