I know about AJAX cross-domain policy. So I can't just call "http://www.google.com" over a ajax HTTP request and display the results somewhere on my site.
I tried it with dataType "jsonp", that actually would work, but I get a syntax error (obviously because the received data is not JSON formated)
Is there any other possiblity to receive/display data from a foreign domain? iFrames follow the same policy?
You can use YQL to do the request without needing to host your own proxy. I have made a simple function to make it easier to run commands:
If you have jQuery, you may use $.getJSON instead.
A sample may be this:
JSONP is the best option, in my opinion. Try to figure out why you get the syntax error - are you sure the received data is not JSON? Then maybe you're using the API wrong somehow.
Another way you could use, but I don't think that it applies in your case, is have an iFrame in the page which src is in the domain you want to call. Have it do the calls for you, and then use JS to communicate between the iFrame and the page. This will bypass the cross domain, but only if you can have the iFrame's src in the domain you want to call.
You can use the technology CORS to configure both servers (the server where the Javascript is running and the external API server)
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
p.s.: the answer https://stackoverflow.com/a/37384641/6505594 is also suggesting this approach, and it's opening the external API server to everyone else to call it.
Unfortunately (or fortunately) not. The cross-domain policy is there for a reason, if it were easy to get around it then it wouldn't be very effective as a security measure. Other than JSONP, the only option is to proxy the pages using your own server.
With an iframe, they are subject to the same policy. Of course you can display the data from an external domain, you just can't manipulate it.
after doing some research, the only "solution" to this problem is to call:
this will ask an user if he allows a website to continue. After he confirmed that, all ajax calls regardless of it's datatype will get executed.
This works for mozilla browsers, in IE < 8, an user has to allow a cross domain call in a similar way, some version need to get configured within browser options.
chrome/safari: I didn't find a config flag for those browsers so far.
using JSONP as datatype would be nice, but in my case I don't know if a domain I need to access supports data in that format.
Another shot is to use HTML5 postMessage which works cross-domain aswell, but I can't afford to doom my users to HTML5 browsers.