【发布时间】:2020-01-14 13:59:05
【问题描述】:
所以当我使用 ajax jquery 和 api 获取请求时,我总是会遇到问题 已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。已尝试使用 js fetch 方法和 jquery 方法。首选jquery方法。总是出现 CORS 错误 已尝试使用 dataType:"json" 已尝试使用 dataType:"jsonp"
$.ajax({
url: "https://login.aupairint.com/api/v1/participant_showcases/au_pair_int.json",
type: "GET",
crossDomain: true,
dataType: "jsonp",
success: function (response) {
var resp = JSON.parse(response)
console.log(resp);
},
error: function (xhr, status) {
console.log("error");
}
});
【问题讨论】:
-
服务器说“不”。更改客户端上的数据类型不会更改“否”上的任何内容。只需在 SO 上搜索“CORS”即可。