跨域AJAX - 这个方法工作吗? [英] Cross-domain AJAX - would this method work?

查看:146
本文介绍了跨域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. 加载iframe中的AJAX调用的URL

  3. 使用JavaScript获取iframe的内容

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

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

推荐答案

是的,您可以对跨网域AJAX使用iframe。它有点复杂(更多如果你想使用XML),但它是可能的。这里有一个很好的文章,描述了几种不同的使用。我认为一个和你描述的非常相似。更重要的是,他描述了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天全站免登陆