Search code examples
javascriptandroidangularjscordovaonsen-ui

Cordova android: Getting 404 error in angular js app


I am developing an application in android using cordova and angularjs (onsenui front end framework). Here is my get request to fetch some data from server

$http.get(url+"getlotterylist").then(function(msg){
        $scope.loading=false;
        $scope.items=msg.data;
    },
    function(err){
        alert("error"+JSON.stringify(err));
          console.log("Error"+JSON.stringify(err));
        }
    );

CASE 1

When running app in browser i will get the desired output (get request works fine).

CASE 2

Build my app in android platform and import to android studio. At this point the http get request returns the following error

{"data":"","status":404,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://example.com?action=getlotterylist","headers":{"Accept":"application/json, text/plain, /"}},"statusText":"Not Found"}"

Also enabled CORS in my php

<?php

  header("Access-Control-Allow-Origin: *");
 //api request response
?>

Why i am getting this error when running my app in phone?


Solution

  • Installing Cordova white-list plugin solves my problem

    https://github.com/apache/cordova-plugin-whitelist