问题跨域Ajax调用 [英] problem with cross-domain ajax calls

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

问题描述

我有两个服务器,一个主站点和一个静态的服务器。 我想从阿贾克斯文件的内容在运行时,它存储在静态的服务器。 显然会出现跨域问题。

i have two servers a main site and a static server. i want to get a file's content from ajax in runtime, which is stored in static server. obviously cross domain problem will occur.

所以我试图做的是保存了AJAX的.js的静态服务器,这样调用本地文件不会是一个问题。

so what i am trying to do is storing that ajax .js in the static server, so that calling the local file wont be a problem.

但之后,我包括的js从静态文件,还是那个问题依然存在......

but after i include that js file from static, still that problem remains...

任何解决方案?!

推荐答案

看看 EasyXDM 。这是它包装跨浏览器的怪癖,并提供了一​​个易于使用的API,使用最好的机制,该浏览器在不同的域之间的客户端脚本通信(如的 postMessage的如果有的话,其他的机制,如果不)。

Take a look at EasyXDM. It's a library which wraps cross-browser quirks and provides an easy-to-use API for communicating in client script between different domains using the best available mechanism for that browser (e.g. postMessage if available, other mechanisms if not).

警告:你必须在两个域控制,以使其工作(其中,控制意味着你可以把他们两个静态文件)。但是,你不需要任何服务器端code的变化。

Caveat: you need to have control over both domains in order to make it work (where "control" means you can place static files on both of them). But you don't need any server-side code changes.

这篇关于问题跨域Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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