2013-05-08 37 views
0

我正在为Phone Gap编写一个应用程序,但无法使用Ajax帖子将变量传递给我的脚本。当我像这样提交时,Ajax帖子工作正常。“lon = 51.02 & lat = 0.00 & ap = 1539”。 但是,当我尝试添加手机间隙变量像这样“lon =”+ PGLon +“& lat =”+ PGLat +“& ap = 1539”我无法让它提交。PhoneGap Veriables No Passing

任何帮助我做错的事情都会很棒。

谢谢你

function onSuccess(position) { 
    var div = document.getElementById('myDiv'); 

    div.innerHTML = 'Latitude: '    + position.coords.latitude + '<br/>' + 
        'Longitude: '   + position.coords.longitude + '<br/>' + 
        'Altitude: '    + position.coords.altitude + '<br/>' + 
        'Accuracy: '    + position.coords.accuracy + '<br/>' + 
        'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br/>' + 
        'Heading: '    + position.coords.heading + '<br/>' + 
        'Speed: '    + position.coords.speed  + '<br/>'; 

    var PGLon = 'Longitude: '    + position.coords.longitude + ''; 
    var PFLat = 'Latitude: '    + position.coords.latitude + '';   
} 

$.ajax({ 
    type: "POST", 
    cache: false, 
    url: "http://MyWebSite.com/uppost.php", 
    data: "lon=" + PGLon + "&lat="+ PGLat + "&ap=1539" , 
    dataType: "json", 
    success: function(data) { 
    alert('Success: The text is now stored in the database.'); 
    } 
}); 

回答

1

试试这个

$.ajax({ 
    type: "POST", 
    cache: false, 
    url: "http://MyWebSite.com/uppost.php", 
    data: {"lon": PGLon , "lat": PGLat , "ap":1539} , 
    dataType: "text", 
    success: function(data) { 
       alert('Success: The text is now stored in the database.'); }, 
    error: function(e){ 
      console.log(JSON.stringify(e)); 
    } 

    }); 
+0

非常感谢你:)该诀窍。 – 2013-05-15 14:15:57