jquery - ASPX API 在 Chrome 浏览器中被阻止
问题描述
$.ajax({
type: "GET",
url: "http://<api URL>/xml_full_new_york.aspx",
contentType: "application/xml; charset=utf-8",
dataType: "xml",
async: true,
error: function (jqXHR, textStatus, errorThrown) {
},
success: function (data) {
$(data).find('stockquotes').each(function () {
var sTitle = $(this).find('CurrentPrice').text();
$('#stockTickerNYSE').text("$" + sTitle);
});
}
});
在 Google Chrome 中,上述 API 被阻止。但它在 IE 浏览器中运行良好。在 Chrome 控制台中,我发现错误:
“通过访问控制检查:请求的资源上不存在 'Access-Control-Allow-Origin' 标头。因此不允许访问 Origin 'null'。响应的 HTTP 状态代码为 403。 "
解决方案
这是CORS问题,您需要添加header("Access-Control-Allow-Origin: *");
后端代码。
推荐阅读
- python - 遵循某些步骤后更改值的布尔值
- oracle - 如何加密 FireDAC 连接以在 Delphi 中使用 TLS/SSL?
- c++ - 如何解决在 n 个数中查找最大数时的运行时错误
- wso2 - 如何配置 wso2 api manager 发布者以加载自定义 local.json 以更改语言
- authentication - Sonos API 中刷新令牌的意义何在
- powershell - 如何通过管道构建 ID 在 ymal json 中获取工件构建版本
- sql - 将具有多行的Json数据插入SQL中的表中
- python - 当 z 为负时,Python 子字符串对 x,y 有什么默认值?(这与 x,y 是否为负无关)
- python - 安装 tensorflow-io kaggle 笔记本时出错
- java - 我的 CSV 阅读器无法识别行首和行尾的缺失值