跨域Ajax - 将这种方法会奏效?这种方法、跨域、Ajax

2023-09-10 17:20:48 作者:天大地大老婆最大〃

我一直在思考了一段时间,如果有一种方式来获得跨域AJAX(使用XML,JSON不是)工作。任何人都可以看到任何理由下是行不通的:

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:

创建一个iframe 加载AJAX调用的URL在iframe 使用JavaScript来获取的iframe 的内容

(这不会是异步的,但是可以使用的setTimeout(functionToLoadTheIframe,1)让你实现异步性?)

(this won't be asynchronous, but could using setTimeout(functionToLoadTheIframe, 1) enable you to achieve asynchronicity?)

推荐答案

是的,你可以使用iframe跨域AJAX。这让有点复杂的(更何况,如果你想使用XML),但它是可能的。这里有一个很好的文章,介绍了所使用的几种不同的黑客。我觉得一个是类似于你所描述的是什么pretty的。更重要的是,他描述了iframe来IFRAME通信这可能会帮助最多的规则。

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