$http.get() not working on Android but is in browser


#1

This code doesn’t work on Android with “ionic run android” but does in the browser with “ionic serve” and Allow-Control-Allow-Origin: * Chrome plugin. No errors in debugger. Any ideas? Thanks, Ben

.factory(‘Api’, function($http) {
return {
domains: function(latlng) {
return $http.get('http://www.nightoutsites.com/json/domains.php?latlng=’+latlng);
}
}
})


#2

Not quite sure what you’re trying to do, but surely you need to chain at least a .success() function on your get statement to get the result??


#3

Added more, but it still only works in the browser and not on my phone where it also logs
In factory
In factory 2

.factory(‘Api’, function($http) {
console.log(‘In factory’);
var d = [];
console.log(‘In factory2’);
return {
domains: function(latlng) {
console.log(‘In factory 3’);
return $http.get('http://www.nightoutsites.com/json/domains.php?latlng=’+latlng)
.success(function(data, status, headers, config){
console.log("**** SUCCESS ");
console.log(status);
})
.error(function(data, status, headers, config){
console.log("
ERROR ****");
console.log(status);
}).then(function(response){
d = response;
console.log('Got some data: ', response);
return d;
});
}
}
})


#4

Hello, did you manage to solve that problem?? I’m suffering the same right now, $http.get is working on IOS and browser but not on Android.


#5

Yes, but it ended up being an issue with how I was handling navigator.geolocation.getCurrentPosition in the controller if I remember correctly.


#6

I’m a little confused by your code, I suspect it may be working more due to luck than design.

What concerns me is the section where you are returning the result of $http.get(). You realise you should be using a callback inside the success function?