简体   繁体   English

AngularJS中不存在“ Access-Control-Allow-Origin”标头

[英]No 'Access-Control-Allow-Origin' header present AngularJS

I am trying to build a quick demo site that I do not have control over the server I am trying to connect to. 我正在尝试建立一个快速演示站点,该站点无法控制我要连接的服务器。 Here is the code that I am using to build it with AngularJS. 这是我用来用AngularJS构建它的代码。 I am running the file through a simple Python HTTP Server and viewing it at localhost:8000. 我正在通过一个简单的Python HTTP Server运行该文件,并在localhost:8000上查看它。 var retrieveAppliances = function () { console.log('Attempting to retrieve appliance list.'); var resolveAppliances = function(){console.log('尝试检索设备列表。');

var requestUrl = '****';
    $http({
        method: 'GET',
        url: requestUrl,
    })
    .then(function (response) {
        console.log(response);
    });
};
retrieveAppliances(); 

I have read multiple places to try switching the method to JSONP but doing so resulted in a parsing error. 我已经阅读了多个地方,尝试将method切换为JSONP但这样做会导致解析错误。

While I have considered trying to build a server.js file and running NodeJS with it, I am unsuccessful in learning the basics of making an AJAX request and proxying that to my app.js. 虽然我考虑过尝试构建一个server.js文件并使用它运行NodeJS,但我没有学习提出AJAX请求并将其代理到我的app.js的基础知识。

I will greatly appreciate any help that someone may be able to give me, with clear and easy to follow steps. 我将不胜感激,因为有人可以通过明确且易于执行的步骤为我提供任何帮助。

If you're running an Ajax call to a different origin (eg different host, port or protocol) and the server at that origin does not have support for cross origin requests, then you cannot fix that from your client. 如果您正在对另一个来源(例如,不同的主机,端口或协议)运行Ajax调用,而该来源的服务器不支持跨来源请求,则无法从客户端修复该问题。 There is nothing you can do from the client. 客户无能为力。

If the server supported JSONP, you could use that, but that also requires specific server support. 如果服务器支持JSONP,则可以使用它,但这还需要特定的服务器支持。

The only solutions from a browser web page are: 浏览器网页上唯一的解决方案是:

  1. CORS support on the target server. 目标服务器上的CORS支持。
  2. JSONP (also requires support on the target server). JSONP(还需要目标服务器上的支持)。
  3. Set up your own server that you do have access to (either on your existing page domain or with CORS) and then have that server get the file/data for you and proxy it back to you. 设置您自己有权访问的服务器(在现有页面域上或使用CORS),然后让该服务器为您获取文件/数据并将其代理回给您。 You can either write your own proxy or deploy a pre-built proxy. 您可以编写自己的代理,也可以部署预构建的代理。
  4. Find some existing third party proxy service that you can use. 查找一些可以使用的现有第三方代理服务。

If you're interested in making your own node.js proxy, you can see a simple example here: How to create a simple http proxy in node.js? 如果您对制作自己的node.js代理感兴趣,可以在这里看到一个简单的示例: 如何在node.js中创建一个简单的http代理? .

暂无
暂无

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

相关问题 AngularJS:所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - AngularJS: No 'Access-Control-Allow-Origin' header is present on the requested resource 不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present 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 不存在“ Access-Control-Allow-Origin”标头。 但是标题存在 - No 'Access-Control-Allow-Origin' header is present. But the header is present CORS标头“ Access-Control-Allow-Origin”丢失,但它出现在标头中 - CORS header 'Access-Control-Allow-Origin' missing but it present in the header AngularJS XMLHttpRequest无法加载X。不存在“ Access-Control-Allow-Origin”标头 - AngularJS XMLHttpRequest cannot load X. No 'Access-Control-Allow-Origin' header present AngularJS'所请求的资源上没有'Access-Control-Allow-Origin'标头'错误 - AngularJS 'No 'Access-Control-Allow-Origin' header is present on the requested resource' error Chrome中的AngularJS CORS问题-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - AngularJS CORS issue in Chrome - No 'Access-Control-Allow-Origin' header is present on the requested resource angularJS和Web API中的请求资源上没有'Access-Control-Allow-Origin'标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource in angularJS and Web API IISNOde中的请求资源(AngularJS + NodeJs)上没有“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource (AngularJS + NodeJs) In IISNOde
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM