I've been thinking for a while if there's a way to get cross-domain AJAX (using XML, not JSON) to work. Can anyone see any reason why the following wouldn't work:
(this won't be asynchronous, but could using setTimeout(functionToLoadTheIframe, 1)
enable you to achieve asynchronicity?)
For a successful cross-domain communication, we need to use dataType “jsonp” in jquery ajax call. JSONP or “JSON with padding” is a complement to the base JSON data format which provides a method to request data from a server in a different domain, something prohibited by typical web browsers.
For instance, if sending a request from http://www.example.com, any of the following would be "cross origin": http://mail.example.com (domain differs) https://www.example.com (protocol differs) http://www.example.com:8080 (port differs)
Parsing JSON was 10 times faster than parsing XML! When it comes to making AJAX behave like a desktop application, speed is everything, and clearly, JSON is a winner. Of course, you might not always have control of the server-side that's producing data for your AJAX application.
Yes you can use iframes for cross domain AJAX. It get's a little complicated (more so if you want to use XML), but it is possible. Here's a good article that describes several different hacks that are used. I think one is pretty similar to what you're describing. More importantly he describes the rules on iframe to iframe communication which will probably help the most.
http://softwareas.com/cross-domain-communication-with-iframes
iframes where used to allow remote calls and "simulate" ajax as we know it today, and the answer is YES...you can use iframes but you have to write sometimes complex client side script using javaScript.
Have you considered using a server side script/application on your domain as a proxy to the remote resource?
That is, send your requests to your script/application on your domain which in turn will fetch data/information from the remote host.
regards,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With