samedi 31 janvier 2015

Not all data sent using $http.post angularjs


why is it that whenever I send data to my server from my mobile application (Ionic Framework) not all data is sent?



$http({
method: 'POST',
url: 'http://remoteserver/data',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: { image: $scope.imgURI,
facebook_id: localStorage.facebook_id,
token: localStorage.accessToken,
location: localStorage.location,
lon: localStorage.longitude,
lat: localStorage.latitude
}
}).success(function (suc)
{
localStorage.removeItem('longitude');
localStorage.removeItem('latitude');
localStorage.removeItem('location');
alert(JSON.stringify(suc));
})
.error(function(err){alert(JSON.stringify(err));});


The location after is undefined when the server receives it. When in fact, I alert it to check if its not empty. How can I fix this? Of all the data sent to my server, only the location is missing. The location is the reversed geocoding of the latitude and longitude. I just put it in my mobile to reduce the over use of Google API since it is per session basis.





Aucun commentaire:

Enregistrer un commentaire