Reputation: 31
I am writing an app in Phone Gap but I cannot get the variables to pass to my script using the Ajax post. The Ajax post works fine when I submit it like this “lon=51.02&lat=0.00&ap=1539”. But when I try and add Phone Gap Variables to it like this “lon=” + PGLon + “&lat=”+ PGLat + “&ap=1539” I cannot get it to submit.
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.');
}
});
Upvotes: 0
Views: 53
Reputation: 4162
Try this
$.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));
}
});
Upvotes: 1