0

I have this URL: https://cdn.static.wizzair.com/en-GB/TimeTableAjax?departureIATA=BUD&arrivalIATA=TLV&year=2016&month=6

which returns me a json. if I go to this URL with my browser or if I'm firing the request using a REST client on my browser (DHC) it works! Now, for me with an express server that runs over https, I'm trying to make this request works using jQuery with no luck.

Somehow the error callback is always being executed even though I see in the network debugging that the request was good and seeing the json response!

My code:

/// 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); }
            });

** * EDIT * **

so I understand this will not work as the target does not support jsonp.

changing it to normal GET request will gets an error and this message:

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.

which is expected. But how come this works on my browser and with the locally rest client? What am I doing wrong?

Thanks!

aviramtsi
  • 89
  • 1
  • 2
  • 9
  • `crossDomain: true,` has no effect on (a) JSONP requests or (b) Requests with aren't pointing to the same origin in the first place. – Quentin May 16 '16 at 11:36
  • Because they do not return JSONP... You can not make a site return JSONP by just adding it, they need to support it. – epascarello May 16 '16 at 11:36
  • `contentType: 'application/json',` — You are making a GET request so there is no request body to describe the content-type of. – Quentin May 16 '16 at 11:37
  • Could you please check the error message, the answer to what's going is probably there ? – Vladimir Drenovski May 16 '16 at 11:37
  • Use `error: function(err) { console.log(err); }`, it will give you a hint what's wrong. – wielo May 16 '16 at 11:43
  • when trying to make it a normal get request I'm getting an object with statusText:"error", and status: 0. also I'm getting the message: `The 'Access-Control-Allow-Origin' header has a value 'https://wizzair.com' that is not equal to the supplied origin`. and that's my I tried JSONP. how come it works in the browser and the rest client locally? – aviramtsi May 16 '16 at 11:51
  • @aviramtsi — That's a completely different question and shouldn't really be an edit of the existing question. It is explained by [this duplicate](http://stackoverflow.com/questions/35553500/xmlhttprequest-cannot-load-https-www-website-com/35553666#35553666) though. – Quentin May 16 '16 at 12:02
  • Well they do not support CORS meaning you can not call that resource with JavaScript in the browser. https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS – epascarello May 16 '16 at 12:09

1 Answers1

1

The URL you are requesting is returning JSON, not JSONP.

JSONP requests only work if the server is designed to respond to them with a JSONP formatted response.

For further reading, see What is JSONP all about


Regarding the significant edit to the question: See this duplicate.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335