【发布时间】:2017-12-14 20:57:27
【问题描述】:
我正在使用网站并访问第三方 api 但出现错误
No 'Access-Control-Allow-Origin' header is present on the requested resource
阿贾克斯:
var headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
headers.append('Accept', 'application/json');
headers.append('content-type', 'application/json');
headers.append('AuthToken', '2948f47085e9d8ecd95bd21ebe024a01516105f9')
headers.append('Access-Control-Allow-Origin', 'http://localhost:61030/Test.aspx');
headers.append('Access-Control-Allow-Credentials', 'true');
$.ajax({
crossDomain: true,
type: "GET",
url: "https://api.travelcloudpro.eu/v1/cache/flyfrom?origin=DEL&pointOfSale=US",
//headers: { '[{"key":"AuthToken","value":"2948f47085e9d8ecd95bd21ebe024a01516105f9","description":""}]': 'some value' },
// header: { 'AuthToken': '2948f47085e9d8ecd95bd21ebe024a01516105f9' },
header:headers,
dataType: "json",
data:{},
success: function (data) {
debugger;
var flightresponse = data;
//alert($("#city").val());
}
});
虽然从邮递员那里调用它工作正常。
我不知道缺少什么,TIA。
如果我将数据类型 json 更改为 jsonp,则会出现此错误:- enter image description here
【问题讨论】:
-
您在邮递员中使用 GET...
-
阅读How to Ask 并分享您的研究。添加随机响应头作为请求头并不能解决问题。
标签: javascript json ajax asp.net-web-api