解決策:angularjsはCORSポリシーによってブロックされています:「Access-Control-Allow-Origin」ヘッダーが...に存在しません



Solution Angularjs Has Been Blocked Cors Policy



最初にハンドルを握る:
https://stackoverflow.com/questions/20754489/access-control-allow-origin-and-angular-js-http

'use strict' angular.module('myApp.view1', ['ngRoute']) .config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'view1/view1.html', controller: 'View1Ctrl' }) }]) .controller('apart1', function ($scope) { $scope.name = 'I am a partamter of app myApp.view3 controller aasdsadsadsd' $scope.userName = 'Please enter a username' $scope.password = 'Please enter a user password' }) .controller('View1Ctrl', function ($scope, $http) { $scope.userNamePlaceholder = 'Please enter a username' $scope.passwordPlaceholder = 'Please enter a user password' $scope.userName = '' $scope.password = '' $scope.aStringInputPlaceholder = 'Please enter the string to be encrypted' $scope.aStringOutputPlaceholder = 'Output encrypted string here' $scope.aStringInput = '' $scope.aStringOutput = '' $scope.requestApiForConverToBase64=function () { $http({ method: 'GET', url: 'https://www.runoob.com/try/angularjs/data/sites.php', headers:{'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Accept': 'application/json'} }).then(function successCallback(response) { $scope.aStringOutput = response.data console.log('--------1') }, function errorCallback(response) { // request failed execution code console.log('--------2') }) } })

コアソリューション:



ヘッダー:{'Content-Type': 'application / json'、
'Access-Control-Allow-Origin': '*'、
'Accept': 'application / json'}