Cross-domain AJAX - would this method work?
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:
- Create an iframe
- Load the URL of the AJAX开发者_StackOverflow社区 call in the iframe
- Use JavaScript to get the content of the iframe
(this won't be asynchronous, but could using setTimeout(functionToLoadTheIframe, 1)
enable you to achieve asynchronicity?)
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,
This would not work due to same domain security restrictions. In most cases you can not interact with frames that have a different domain. Otherwise a malicious site could load your email inbox for example.
精彩评论