Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does $http work in phonegap?

I'm using angular-phonegap-seed to write a mobile app, and was wondering if there were any known issues with using $http.

My controller code is called on the push of a button.

$http.get('http://192.168.1.2:8000/request_token').success(function(data, status, headers, config){
    $scope.token = 'sucess: ' + data + ' ' + status + ' ' + headers + ' ' + JSON.stringify(config);
}).error(function(data, status, headers, config){
    $scope.token = 'error: ' + data + ' ' + status + ' ' + headers + ' ' + JSON.stringify(config);
});

At the moment, request_token on the server is simply a file with a dummy token in it.

The server acknowledges getting the request in the console and responds with 200. The phonegap app on android however responds:

error: undefined undefined undefined {"transformrequest": [NULL], "transformresponse": [NULL], "method": "GET", "url": "http://server-ip:8000/request_token", "headers": {"accept": "application/json, text/plain, */*"}}

Can I use the regular $http.get() method in phonegap, or do I have to use a phonegap api?

like image 693
lowerkey Avatar asked Mar 23 '23 04:03

lowerkey


1 Answers

In my case, it turns out to be that I forgot about whitelisting the domains I was sending request to.

Check out the Domain Whitelist Guide and see if it helps.

like image 116
Justin Lau Avatar answered Apr 02 '23 23:04

Justin Lau