Answer the question
In order to leave comments, you need to log in
How to make a GET request in angularjs?
Good day, when trying to make a request, AngularJS gives an error like
XMLHttpRequest cannot load http://127.0.0.1:8000/api/cat/2/.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:63342' is therefore not allowed access.
function MainCtrl ($scope, $http, $log) {
$http({
method: 'GET',
url:"http://127.0.0.1:8000/api/cat/2/"
})
.success(function (response) {
$scope.myResp = response.data;
$log.info(response);
});
}
angular
.module("app", [])
.controller("MainCtrl", MainCtrl);
Answer the question
In order to leave comments, you need to log in
You can try $http.jsonp. Cross-domain requests with Ajax are not so easy to send.
It is necessary to set the allow-origin:* header on the server. Google cors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question