Error consuming service

1

I have a problem when consuming a Rest service with Jquery, I have no problem with tools like Insomnia or the browser.

$.ajax({
   type: "GET",
   url: "http://sanguchi.esy.es/peoples",
   contentType: 'application/json',
   dataType: "json",
   success: function (data) { 
       alert("success");
   },
   error: function (jqXHR, status) { 
         alert("error"); //Siempre ejecuta esto
       }
});

What should return is the following:

[{ "id": "1","nombre": "aaaa" }, {"id": "2",  "nombre": "bbb"}   ]
    
asked by Chipilo 10.08.2016 в 01:02
source

1 answer

1

Knowing that you use hostinger, you walk PHP in the backend then add the header:

 <?php
 header("Access-Control-Allow-Origin: *");

and / or in your file .htaccess :

Header set Access-Control-Allow-Origin "*"
    
answered by 10.08.2016 / 02:21
source