I am using, for the first time, angularJs and I would do a thing very simple, but I don't know what I wrong. I have my code in my local env and the API is on web (I used free tool to create a simple API).
I created this simple API: http://www.mocky.io/v2/5a1fedce310000221bc0b08b
that return:
{"id" : 1, "name" : "France - Mainland", "desc": "some description" },
{"id" : 2, "name" : "Gibraltar", "desc": "some description"},
{"id" : 3, "name" : "Malta", "desc": "some description"}
Now I have my app.js
(function () {
'use strict';
angular.module('test', []).controller('DemoCtrl', function ($scope, $http) {
$scope.selectedTestCountry = null;
$scope.testCountries = [];
$http({
method: 'GET',
url: 'http://www.mocky.io/v2/5a1fede63100005d1ec0b08f',
data: { someId: 3 }
}).then(function (result) {
$scope.testAccounts = result;
}).catch(function (err) {
$scope.error = err}
);
});
})()
The problem is, when the call is made, I got an error.
From Chrome I got this error:
- Failed to load resource: the server responded with a status of 403 (Forbidden)
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.
I read something that suggest to change browser, for example use FF.
But in FF I have an other error:
Bloccata richiesta multiorigine (cross-origin): il criterio di corrispondenza dell’origine non consente la lettura della risorsa remota da http://www.mocky.io/v2/5a1fede63100005d1ec0b08f. Motivo: header CORS “Access-Control-Allow-Origin” mancante. (sorry is in italian, but it means there are some issue with CORS)
In the end, if I print the error in catch, I got this:
{"data":null,"status":-1,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"http://www.mocky.io/v2/5a1fede63100005d1ec0b08f","data":{"applicationId":3},"headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"","xhrStatus":"error"}
Please help me.
Thanks