沒有“訪問-控制-允許-原產(chǎn)地”-節(jié)點(diǎn)/Apache端口問題我使用Node/Express創(chuàng)建了一個(gè)小API,并試圖使用Angularjs來提取數(shù)據(jù),但是當(dāng)我的html頁面在localhost上Apache下運(yùn)行時(shí):8888,節(jié)點(diǎn)API在端口3000上偵聽,我得到的是No‘Access-Control-ALL-原產(chǎn)地’。我嘗試使用節(jié)點(diǎn)-http-代理和VhostApache,但沒有多少成功,請參閱下面的完整錯(cuò)誤和代碼。“XMLHttpRequest無法加載localhost:3000。請求的資源上不存在”訪問-控制-允許-原產(chǎn)地“標(biāo)頭。因此,不允許訪問源‘localhost:8888’?!?/ Api Using Node/Express var express = require('express');var app = express();var contractors = [
{
"id": "1",
"name": "Joe Blogg",
"Weeks": 3,
"Photo": "1.png"
}];app.use(express.bodyParser());app.get('/', function(req, res) {
res.json(contractors);});app.listen(process.env.PORT || 3000);console.log('Server is running on Port 3000')
// Angular code
angular.module('contractorsApp', [])
.controller('ContractorsCtrl', function($scope, $http,$routeParams) {
$http.get('localhost:3000').success(function(data) {
$scope.contractors = data;
})
// HTML
<body ng-app="contractorsApp">
<div ng-controller="ContractorsCtrl">
<ul>
<li ng-repeat="person in contractors">{{person.name}}</li>
</ul>
</div>
</body>
沒有“訪問-控制-允許-原產(chǎn)地”-節(jié)點(diǎn)/Apache端口問題
叮當(dāng)貓咪
2019-06-21 17:07:29