The functionality of making Slim POST requests is currently not functioning as expected within the Ionic

An issue is arising with my app that makes calls to a REST API using POST and GET methods. The app I'm developing with Ionic works perfectly when emulated using the command:

ionic serve --lab

However, when running the app on an actual device, calls to the API result in a 404 error. Below are details of my app:

app.constants.js:

.constant('REST_SERVICE', {
    url: 'http://skulapp.com/nuevo/service',
    services: {
        profile:              '/get_profile/profile'/*,
        contacto:           '/contactos/',
        contactosExport:     '/contactosExport/',
        campanna:           '/campannas/',
        sync_contactos:     '/sync_contactos/',
        sync_campannas:     '/sync_campannas/'*/
    }
})

app.controller.js: This function utilizes the service: _Auth_Service

$scope.login = function(_credentials){
        if(_credentials != null){
            $ionicLoading.show({
                template: '<ion-spinner icon="lines" class="spinner-calm"></ion-spinner>'
            });
            _Auth_Service.verify({user: _credentials.user, pass: hex_md5(_credentials.pass)}).then(function(profile){
                $state.go('main.dashboard', {}, {reload: true});
                //console.log(profile);
                $scope.setCurrentUsername(profile);
                $ionicLoading.hide();
            }, function(err) {
                var alertPopup = $ionicPopup.alert({
                    title: 'Usuario no Valido',
                    template: 'Por favor revise su usuario y contraseña'
                });
                $ionicLoading.hide();
            });
        } else
            var alertPopup = $ionicPopup.alert({
                title: 'Inicio Cancelado',
                template: 'Ingrese su usuario y contraseña'
            });
    }

app.services.js: Service _Auth_Service, use service _API

    .service('_Auth_Service', function($q, $http, _API, USER_ROLES){

        var authService = {};
        var LOCAL_TOKEN_KEY = 'LocalAppToken';
        var username = '';
        var isAuthenticated = false;
        var role = '';
        var authToken;

        authService.verify = function(credentials){
            return _API.get('profile', credentials).then(function(res){
                console.log(res);
                storeUserCredentials(credentials.user + '.yourServerToken');
                storeUserRol(res.data[0].Rol_USU)
                return res.data[0];
            });
        };

        ... (omitting some lines for brevity)

        loadUserCredentials();

        return {
            login: login,
            logout: logout,
            isAuthorized: isAuthorized,
            isAuthenticated: function() {
                return isAuthenticated;
            },
            username: function() {
                return username;
            },
            role: function() {
                return role;
            }
        };
    })

.service('_API', function($http, REST_SERVICE){

    this.get = function(_service, _data){
        var _url = REST_SERVICE.url+REST_SERVICE.services[_service];
        ... (omitting some lines for brevity)
        return $http.get(_url);
    }

    this.post = function(_service, _data){
        var _url = REST_SERVICE.url+REST_SERVICE.services[_service];
        //console.log(_data);
        return $http.post(_url, _data);
    }

})

REST API: get_profile/profile

$app->group('/get_profile', function() use($app){

        $app->post('/profile', function() use($app){
            try{
                
                ... (omitting some lines for brevity)

                $_sql = 'SELECT u._id_PER, p._id_IMA, p.Nombre_PER, p.Apellidos_PER, p.Identificacion_PER, p.Telefono...';

                ... (omitting some lines for brevity)

            }catch(PDOException $e){
                $app->response->status(500);
                echo "Error: Descargando los datos " . $e->getMessage();
            }
        });

        ... (omitting some lines for brevity)

});

If you wish to test the service, please use the following URL:

Answer №1

After encountering an issue, the solution I found was to incorporate the whitelist plugin and make specific configurations in my config.xml file:

<allow-navigation href="http://skulapp.com/*" />
  <access origin="http://skulapp.com" />
  <access origin="*"/>
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
  <allow-intent href="sms:*" />
  <allow-intent href="mailto:*" />
  <allow-intent href="geo:*" />
  <platform name="android">
    <allow-intent href="market:*" />
  </platform>
  <platform name="ios">
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
  </platform>

https://github.com/apache/cordova-plugin-whitelist and https://github.com/phonegap/phonegap-start/blob/master/www/config.xml (acknowledgments to Nicholls)

I realized that a particular domain needed to be accessed, but it wasn't on my whitelist. Utilizing this plugin allowed me to configure these details effectively by adding the desired domain, ultimately resolving the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to showing pictures from the public directory in Laravel version 5.8?

I have been attempting to showcase an image that is stored in the storage/app/uploads directory. Even after running the "php artisan storage:link" command successfully, the image is still not appearing. Upon inspecting the code in the browser, I can see ...

Text alignment issues cause animation to vanish

Utilizing particles.js, I set up a full-screen particle effect by specifying the animation to be full-screen with height: 100vh;. This worked perfectly as intended. However, when attempting to add text on top of the particle animation and center it vertica ...

The Bootstrap 4 card component is a versatile and stylish

Currently working on a display layout using Bootstrap 4, specifically utilizing cards. The issue I'm facing is that the text exceeds the limit of the card, causing it to overflow. Is there a solution to make the text automatically wrap to the bottom ...

Remove buttons from carousel elements in React Multi-Carousel

Is there a way to hide the arrows in the react-multi-carousel component? https://i.stack.imgur.com/V1nix.png ...

Designing a carousel-style menu list with navigation buttons for moving forward and backward

I'm running into some trouble while attempting to create a carousel. Firstly, the issue I am facing is that when you continuously click on the Next button, the function keeps working even after reaching the last item. I'm not sure how to make th ...

Utilize several conditions in Doctrine Query Language for enhanced querying capabilities

In my database, there is a column named "refused" which can have values of 0, 1, or NULL. I am trying to retrieve rows that only have values of 0 and NULL. My attempt so far has been using the following code: ->andWhere('b.refused IS NULL') ...

ng-model is not defined when used with ng-if, but it functions properly with ng-show

I've encountered an issue with my basic functionality where I am trying to retrieve the text value on a click event. There is a text box inside an ng-if directive, but when attempting to get the value, it returns 'undefined'. After some rese ...

The verified class jetstream does not exist

Recently, I decided to dive into Laravel 10 and installed Jetstream. To check my routes using php artisan route:list in the console, an error popped up stating: Class "verified" does not exist. Even though I have declared verified in my Kernel: ...

Calling an ajax request to view a JSON pyramid structure

My experience with ajax is limited, so I would appreciate detailed answers. I have a Pyramid application where I need to load information via ajax instead of pre-loading it due to feasibility issues. I want to retrieve the necessary information through a ...

Testing AngularJS components with header response verification

After a successful login on my web, the backend sends me an 'x-token'. In my frontend, I validate this token by setting $rootScope.authenticated = true;. If the token is missing from the header response for any reason, my frontend sets $rootScope ...

Fetch the Future<list<DATA>> array from an API in Flutter and parse the JSON response

I recently dove into Flutter and decided to start using FlutKit packages. I've encountered a challenge with an array LIST while working on this project. FlutKit utilizes a list with static Json data to cache initial data, including Products, Categorie ...

A guide to setting an href using variable values in jQuery through manual methods

I have a datepicker set up where each day, month, and year is stored in a variable. I then display this information in the desired format. Below is the jQuery code: jQuery(document).ready( function($){ alert('alert function'); var txtFr ...

When sending a single apostrophe as a parameter in an AJAX post request, it will result in an error

JavaScript Code: var name = jQuery("#name1").val(); jQuery.ajax({ url: siteUrl + 'search/ind', type: 'POST', data: { name: name, }, success: function(data) { jQuery('#input').val(''); } } ...

Leverage the power of rxjs to categorize and organize JSON data within an

I am in need of reformatting my data to work with nested ngFor loops. My desired format is as follows: this.groupedCities = [ { label: 'Germany', value: 'de', items: [ {label: 'Berlin', value: 'Berlin ...

Modifying the row background in a DataTables drawCallback

Is there a way to dynamically change the background color of a row based on a specific value in a cell using drawCallback? $(table_id).DataTable({ //... "drawCallback": function (settings) { // Here, if the type of data in a particular ce ...

In-Memory PHP and SQLite Collaboration

I have a unique and innovative responsive HTML page. Within this page, there is an exceptional product search section. Users are provided with the opportunity to enter their desired search criteria into a carefully designed form and instantly receive relev ...

Tips for sending parameters to XSLT using a Javascript function

Despite my efforts to find a solution in various online posts, I haven't been able to resolve the issue. The challenge lies in my HTML file that includes a JavaScript function for parsing XML and rendering XSLT. I have multiple 'records' in ...

What is the reason for receiving this £10 with charset=utf8?

When I input a £ symbol into my database, why does it consistently show as £? I initially believed this issue was related to the charset, but I assumed using utf8 would resolve it. UPDATE: I am currently setting the charset like so: $db = new PDO(&a ...

Develop a collection of data entries and add them to a database at a later time using

To track and log the users entering different subpages, I am looking to store this information in a MySQL table. The table will contain details such as userid, subpage, subpageid, and datetime. function logstore(){ global $DB, $USER, $CFG; $protocol = s ...

Is there a way to display (PHP for loop variables) within an HTML table using echo?

for ($q = 1 ; $q < 7 ; $q++ ) { echo $q ; echo $row; } While the above code functions properly, I am interested in echoing two rows as shown in the image below: https://i.stack.imgur.com/7KmUY.jpg I prefer not to use another for loop. Is there a way t ...