我想使用 JSONP。
我在编写这样的代码时遇到了这个错误:
请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' http://localhost '。
问题是什么?
function getAirLine(from , to , date) {
var href = "https://api.flightstats.com/flex/schedules/rest/v1/json/from/"+from+"/to/"+to+"/departing/"+date+"?appId=[myKey1]&appKey=[myKey2]&extendedOptions=languageCode:ko";
$.ajax({
url : href,
dataType: 'jsonp',
success : function(datas) {
console.log(datas);
var dataSet = [];
for (var i = 0; i < datas.scheduledFlights.length; i++) {
for(var j = 0 ; j < datas.appendix.airlines.length ; j++){
if(datas.scheduledFlights[i].carrierFsCode == datas.appendix.airlines[j].fs){
airlines = datas.appendix.airlines[j].name;
}
}
var dataArr = [];
dataArr.push(datas.scheduledFlights[i].departureAirportFsCode);
dataArr.push(datas.scheduledFlights[i].departureTime.substring(11,16))
dataArr.push(datas.scheduledFlights[i].arrivalAirportFsCode)
dataArr.push(datas.scheduledFlights[i].arrivalTime.substring(11,16))
dataArr.push(datas.scheduledFlights[i].carrierFsCode + datas.scheduledFlights[i].flightNumber)
dataArr.push(airlines);
dataSet.push(dataArr);
}
console.log(dataSet);
$('#realTime').DataTable({
destroy: true,
data: dataSet,
columns: [
{ title: "From" },
{ title: "Depart.Time" },
{ title: "To" },
{ title: "Arrial.Time" },
{ title: "AirLine" },
{ title: "AirCode" }
]
});
},
error: function(datas) {
console.log('실패 - ', datas);
}
});
}
我们应该如何解决?
相关分类