[英]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: 浏览器网页上唯一的解决方案是:
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.