跨域Ajax - 将这种方法会奏效? [英] Cross-domain AJAX - would this method work?

查看:106
本文介绍了跨域Ajax - 将这种方法会奏效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在思考了一段时间,如果有一种方式来获得跨域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:

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

(这不会是异步的,但是可以使用的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

这篇关于跨域Ajax - 将这种方法会奏效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆