javascript - Jquery Json错误,来自steam的json,Access-Control-Allow-Origin

标签 javascript php jquery json ajax

我遇到了一个问题,与 here 的问题相同。但我不明白他的意思

What you need to do is introduce a middle-ware, so have your back-end server to make a request against steamcommunity.com and return the same response, and make the ajax call against you're server. This will work, your back-end is sending the request, and as it is not a browser request, the response will land, than your ajax call will be able to get the response as well since it is issued against the same domain.

我得到的错误是“Access-Control-Allow-Origin”和 here他说为什么我会得到这个,所以我问如何“解决”这个问题。

我的后端服务器如何向 steamcommunity.com 发出请求并对我的服务器(Xampp Localhost)发出 ajax 调用?那么具体的解决方案是什么呢?有地方有文档或教程吗?有人可以制作一个代码示例(或者告诉我在哪里可以编写此代码,因为我假设根据答案,您无法使用浏览器请求 json(在网站代码内)),否则我将无法得到它。

最佳答案

How can my back-end server make a request against steamcommunity.com and a ajax call against my server(Xampp Localhost)?

不能,但这不是您引用的 Material 所说的应该做的。

Ajax 调用是由浏览器而不是服务器进行的。

内容是这样的:

  1. 您的 JavaScript 向您的服务器发出 HTTP 请求(该服务器与提供运行 JS 的 HTML 文档的服务器相同,这意味着 HTTP 请求是向同源发出的)。
  2. 您的服务器向 Steam 服务器发出 HTTP 请求
  3. Steam 的服务器向您的服务器发出 HTTP 响应
  4. 您的服务器处理该响应并使用其中的数据向浏览器中运行的 JavaScript 发出 HTTP 响应。

关于javascript - Jquery Json错误,来自steam的json,Access-Control-Allow-Origin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33680055/

相关文章:

Javascript 对象实例化类似于 php new $className();

javascript - CHART.JS 如何偏移/移动/调整 y 轴上的标签使其位于网格线的中间而不是在网格线的中心?

php - 使用 JQuery Ajax 调用 php 函数

jQuery 角落插件无法在 Internet Explorer 上运行

Javascript/Jquery boolean 帮助 : Hiding/Showing Divs

javascript - 如何测试变量是否使用 typeof 设置?

javascript - 如何在jquery/script中传递用户输入数据?我正在使用 codeigniter php 框架

php - 显示该国家世界排名前 5% 和 10% 的奖杯 [按百分比排名系统]

php - 如何将秒转换为时间格式?

javascript - 在 jQuery 脚本中调用时 PHP 变量为空