0

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

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

1 回答 1

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

  });
于 2013-05-08T14:59:40.903 回答