我有这个网址:https://cdn.static.wizzair.com/en-GB/TimeTableAjax?departureIATA=BUD&arrivalIATA=TLV&year=2016&month=6成功回调永远不会调用的JSONP请求
返回我JSON。如果我使用浏览器访问此URL,或者如果使用浏览器上的REST客户端(DHC)发起请求,它可以正常工作!现在,对于运行在https上的快速服务器,我试图使用jQuery工作,但没有运气。
不知何故错误回调总是在执行,即使我在网络调试中看到请求很好并且看到了json响应!
我的代码:
/// removed old code ///
$.ajax({
method: 'GET',
url: "https://cdn.static.wizzair.com/en-GB/TimeTableAjax?departureIATA=BUD&arrivalIATA=TLV&year=2016&month=6&callback=?",
dataType: "jsonp",
success: function() { console.log("success"); },
error: function(err) { ;console.log(err); }
});
** *编辑* **
让我明白,这将无法正常工作的目标不支持JSONP。
它改变到正常GET请求意愿得到一个错误,该信息:
XMLHttpRequest cannot load https://cdn.static.wizzair.com/en-GB/TimeTableAjax?departureIATA=BUD&arrivalIATA=TLV&year=2016&month=6 . The 'Access-Control-Allow-Origin' header has a value ' https://wizzair.com ' that is not equal to the supplied origin. Origin ' https://localhost:3000 ' is therefore not allowed access.
预计。但是,如何在浏览器和本地休息客户端上运行?我究竟做错了什么?
谢谢!
'crossDomain:true,'对于(a)JSONP请求或(b)请求没有影响,并且首先没有指向同一个来源。 – Quentin
因为他们不返回JSONP ...你不能通过添加它来使一个网站返回JSONP,他们需要支持它。 – epascarello
'contentType:'application/json',' - 您正在发出GET请求,因此没有请求主体来描述内容类型。 – Quentin