This is what i'm trying to do:
function fetch() {
$http.get("")
.success(function(response) {
console.log(response);
$scope.details = response;
});
};
The error i'm receiving is the following:
XMLHttpRequest cannot load . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I've looked up quite a bit on this issue or CORS but still can't seem to realize what i have to add and in which file(s).
This is what i'm trying to do:
function fetch() {
$http.get("http://www.myapifilms./imdb/top")
.success(function(response) {
console.log(response);
$scope.details = response;
});
};
The error i'm receiving is the following:
XMLHttpRequest cannot load http://www.myapifilms./imdb/top. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I've looked up quite a bit on this issue or CORS but still can't seem to realize what i have to add and in which file(s).
Share Improve this question asked Dec 9, 2015 at 22:06 TempuslightTempuslight 1,2234 gold badges20 silver badges41 bronze badges 2- Use JSONP in this case. – dfsq Commented Dec 9, 2015 at 22:11
-
I've tried the following:
function fetch() { $http.jsonp("http://www.myapifilms./imdb/top") .success(function(response) { $scope.details = response; console.log(response); console.log(details); }); };
But can't seem to get a console log going and details isn't getting filled up? – Tempuslight Commented Dec 9, 2015 at 23:11
3 Answers
Reset to default 4This means that http://www.myapifilms. does not allow "localhost" origin to access its data.
I could remend two solutions:
try using http-server by running
npm install -g http-server
download a chrome plugin(not remended) but can be handy for testing https://chrome.google./webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?utm_source=chrome-app-launcher-info-dialog
For this request to succeed, the response from myapifilms. would need the correct headers set. What you should do is route your request through a server of your own. However you could get around it for testing purposes with a browser extension
Explained in detail here.
use this plugin: https://chrome.google./webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en
//make headers for service
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('appCurrentVersionNumber', AppConstant.APP_VERSION);
headers.append('WebServiceIdentifier', AppStorage.getItem('webserviceidentifier'));
this.headers = {headers}; this.http.post(API_URL + 'checkInVan', JSON.stringify(userData), this.headers).map(res => res.json());
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745411106a4626537.html
评论列表(0条)