我正在尝试使用jQuery ajax调用访问以下URL ..
Ajax调用
$.ajax({
type:"GET",
url: 'https://affiliate-api.flipkart.net/affiliate/report/orders/detail/xml?startDate=2015-05-01&endDate=2015-05-30&status=Pending&offset=0',
beforeSend: function(xhr) {
xhr.setRequestHeader("Fk-Affiliate-Id", "XXXXXX");
xhr.setRequestHeader("Fk-Affiliate-Token", "YYYYYYYYYYYYY");
},
success: function(data){
$('#response').html(data);
}
});
我收到以下错误..
阻止跨源请求:同源策略禁止在https://affiliate-api.flipkart.net/affiliate/report/orders/detail/xml?startDate=2015-05-01&endDate=2015-05-30&status=Pending&offset=0读取远程资源。 (原因:缺少CORS标题'Access-Control-Allow-Origin'。
阻止跨源请求:同源策略禁止在https://affiliate-api.flipkart.net/affiliate/report/orders/detail/xml?startDate=2015-05-01&endDate=2015-05-30&status=Pending&offset=0读取远程资源。 (原因:CORS请求失败)。
答案 0 :(得分:-2)
你需要使用jsonp来修复它
$.ajax({
type: 'GET',
url: "[]",
jsonp: 'callbackme',
dataType: "jsonp",
xhrFields: {
withCredentials: false
},
headers: {
'Fk-Affiliate-Id': 'xxxx',
'Fk-Affiliate-Token': 'xxxxxxxxxxxxxxxxxxxxxx',
'Content-Type': 'application/json'
},
success: function(data) {
for (i = 0; i < data.allOffersList.length; i++)
alert(data.allOffersList[i].title);
},
}); //end ajax