Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$http call won't work on Ionic Android build

This is how I'm making the call:

$http.get( url, {
    params : {
        empId: $scope.empId
    }
}).then(function(data, status){
    $scope.workOrders = data.data;
}, function(data, status){
    $scope.message = data;
});

It works just fine on Chrome, and if I navigate to the URL on my phones browser I can get a response just fine.

However, whenever I use the .apk that gets built I get:

{"data":"",
 "status":404,
 "config":{
     "method":"GET",
     "transformRequest":[null],
     "transformResponse":[null],
     "params":{"empId":"123"},
     "url":"http://...",
     "headers":{"Accept":"application/json, text/plain, */*"}
 },"statusText":Not Found"}

Kinda lost on this one. Just weird that I can hit the URL from my phone browser but not within the Ionic/Cordova built .apk

As requested, here is my config.xml file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.myapp397384" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>myApp</name>
  <description>
        An Ionic Framework and Cordova project.
    </description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">
      Ionic Framework Team
    </author>
  <content src="index.html"/>
  <access origin="*"/>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="BackupWebStorage" value="none"/>
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
</widget>
like image 461
Hoser Avatar asked May 16 '15 02:05

Hoser


Video Answer


1 Answers

Aha!

Apparently Cordova just released cordova-android 4.0 not too long ago and it by default blocks http requests.

Just run this command:

ionic plugin add cordova-plugin-whitelist

And you're good to go.

like image 126
Hoser Avatar answered Sep 30 '22 00:09

Hoser