简体   繁体   English

请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许Origin'http:// localhost:8100'访问

[英]No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access

server.js where i've declared the permissions server.js我已经声明了权限

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

app.js app.js

angular.module('app', ['ionic', 'ui.router'])

.config(('$urlRouterProvider', '$stateProvider', function($urlRouterProvider,$stateProvider){
    $urlRouterProvider.otherwise('/');
    $stateProvider
    .state('view',{
      url:'/',
      templateUrl:'js/components/view/view.html',
      controller:'viewCtrl'
    })

}))

view.js view.js

.controller('viewCtrl',['$scope','$state','$http',function($scope,$state,$http)
{   

    $scope.pics=[];
    $http.get('http://localhost:8080/getNewPhoto').then(function(response){
        $scope.pics=response.data;
    },function(err)
    {
        console.error("There's an error"+err);
    })
}])

kindly help me out in this problem I've tried all possible solution but the problem is still there 请帮助我解决这个问题我已经尝试了所有可能的解决方案,但问题仍然存在

Simply use cors module of express and you will be fine: 只需使用快递的cors模块 ,您就可以了:

var express = require('express')
var cors = require('cors')
var app = express()

app.use(cors())

You must add an important header. 您必须添加一个重要的标题。 Add that line to server script: 将该行添加到服务器脚本:

res.header('Access-Control-Allow-Methods','POST, GET, OPTIONS, PUT');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 - 请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许Origin'http:// localhost:8100'访问 - — No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost:4400” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4400' is therefore not allowed access Socket.io没有'Access-Control-Allow-Origin'标头出现在请求的资源上。 因此不允许Origin'http:// localhost'访问 - Socket.io No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost:4200” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed accesss AngularJS:所请求的资源上不存在“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空” - AngularJS : No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access Golang 请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许访问原点 'null' - Golang No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问源“ file://”。 - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'file://' is therefore not allowed access. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access 请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin '...' 因此不允许访问 - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM