我正在使用Phone Gap编写应用程序,但我无法使用Ajax帖子将变量传递给我的脚本。当我提交这样的“lon = 51.02& lat = 0.00& ap = 1539”时,Ajax帖子工作正常。 但是当我尝试添加Phone Gap变量时,就像这样“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.');
}
});
答案 0 :(得分: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));
}
});