1

I try to use Angularjs http service to call my PHP API. Everything working fine in Browser. But, when I test it on my Android Phone, it will not work.

My Issue:

In Android PhoneGap Application, Whenever I trigger the Angularjs http service it will always trigger the function (error) even when the Mobile is connected with Internet.

I have try look this but their solution aren't working:

  1. Angular $http.get() does not work in Phonegap DevApp
  2. Cordova 5.3.1 Android app can't access the internet

I also have ensure the Phonegap config.xml has allowed Internet Permission Access with:

<access allows-arbitrary-loads-in-media="true" allows-arbitrary-loads-in-web-content="true" allows-local-networking="true" origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />

However it is still not Working.

My Question:

  1. Is Angularjs http service is not able to work on PhoneGap Mobile Application but only Web Browser?
  2. Aside from config.xml , is there any other configuration have to be made to allow PhoneGap Mobile Application to access the Internet?

Angularjs code:

$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';

$http({
    method: 'POST',
    data: {
        'email' : $scope.email,
        'password' : $scope.password,
    },
    url: 'https://unsurfaced-cross.000webhostapp.com/PGLogin.php'
 }).then(function (response){
    $scope.users = response.data;

    if(response.data[0]=="LOGIN"){
      alert("Successful Login");
      $window.location.href = './homepage.html';

    }else{
      alert("Login Failed. Incorrect Email or Password.");
    }

 },function (error){
      alert("Please ensure You are connected to Internet.");
 });
1
  • What does the error in the error callback say? Commented Apr 16, 2018 at 17:39

1 Answer 1

0

seem like actually I just didn't install the whitelist plugin, for my case the whitelist plugin didn't installed by Default.

Since I was using PhoneGap, instead of using command like cordova-plugin-whitelist@latest, cordova create, cordova plugin add cordova-plugin-whitelist or etc.

I should use: phonegap plugin add cordova-plugin-whitelist

After install the Whitelist Plugin, everything working fine.

So,

  1. Angularjs http service is able to work on PhoneGap Mobile Application.
  2. Aside from config.xml , we have to ensure that all necessary and required plugin was installed such as Whitelist plugin.
Sign up to request clarification or add additional context in comments.

1 Comment

this doesn't work for me, also I added and removed the plugin for making sure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.