Ajax can not connect to server

0

I made a mobile app using phonegap. I use Ajax to fetch data from a server. On the server there is a webservice made in Laravel, which returns the data in json. This is the code:

jQuery(function($) {
            $(document).ready(function() {
                $(".loader").show();
                $.ajax({
                    url: 'http://miIp/public/menu',
                    dataType: 'json',
                    success:function(data){
                        $("#conectionError").hide();

                        if(data == 1){
                            $('#liveStreaming').show();
                            $("#live_choose").show();
                            $(".btn_menu").hide();
                        }
                        if(data == 0){
                            $('#liveStreaming').hide();
                            $("#live_choose").hide();
                            $(".btn_menu").show();
                            $('#liveStreaming').hide();
                        }
                        $(".loader").fadeOut("slow");
                    },
                    error:function(){
                        $(".loader").hide();
                        var divHeight = $("#conectionError").height();
                        var imgHeight = $("#conectionErrorImg").height();
                        var imgMargin = (divHeight - imgHeight)/2;

                        $("#conectionErrorImg").css("margin-top", imgMargin);

                        $("#conectionError").show();
                    },
                    async: true
                });
            });
        });

I tried the application locally. The laravel application had it in xampp, and it worked perfectly. I even compile the app with phonegapp, I installed it, and it worked perfectly.

Today I uploaded the laravel app to a cloud server in WIROOS, and the app does not bring anything. I paste the links in the browser and it brings me the data correctly, but ajax always goes through the error, it never connects.

I assumed that maybe it is some problem of permissions (I am using Vesta Panel), but I can not understand what happens.

Does anyone have any ideas?

    
asked by Ezequiel Romano 12.04.2018 в 20:46
source

1 answer

0

I think it's a CORS problem, which you must configure on your server to be able to consume from your app. And what do you use Laravel, I recommend you use the package barryvdh / laravel-cors

With this package you can configure control headers for CORS using the Laravel Middleware.

I recommend reading a bit about CORS so that you have a rough idea of why you can not access the resources of your server from the app: link

I hope I helped something. Greetings.

    
answered by 13.04.2018 в 00:01