2013-05-08 115 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