简体   繁体   English

跨服务器AJAX呼叫

[英]Cross Server AJAX Call

I found a couple of posts that solved this problem for others, but not for my situation. 我发现了一些帖子可以解决其他问题,但不是我的情况。 I would like to get the best solution possible for my cross server ajax call. 我想为我的跨服务器ajax调用获得最佳解决方案。

Here's the situation. 这是情况。 I have two urls, www.mysite.com and members.mysite.com. 我有两个网址,www.mysite.com和members.mysite.com。 The first site is wordpress driven and the second is codeigniter driven, I refer to these sites as wordpress side and codeigniter side. 第一个站点是wordpress驱动,第二个站点是codeigniter驱动的,我将这些站点称为wordpress side和codeigniter side。 The codeiginter side has a calendar page of events that is created as a module so all any page has to do is include the file and all javascript and stuff comes with it. codeiginter端有一个事件的日历页面,作为一个模块创建,所以任何页面所要做的就是包含文件和所有的javascript和东西随附。 On the wordpress side, we have to include one of these files into a page, but the problem is that the codeigniter side is ajax driven, so when it does the ajax calls, the calls will be cross server. 在wordpress方面,我们必须将其中一个文件包含在一个页面中,但问题是codeigniter端是ajax驱动的,所以当它执行ajax调用时,调用将是跨服务器的。 Here are the solutions that I've seen on the web with the cons in my situation: 以下是我在网上看到的解决方案,在我的情况下有缺点:

  1. jsonp - This doesn't support POST data. jsonp-这不支持POST数据。
  2. simple server side proxy http://devlog.info/2010/03/10/cross-domain-ajax/ - Since the javascript is shared between the two urls, I'll have to create the same file on both the wordpress side and the codeigniter side. 简单的服务器端代理http://devlog.info/2010/03/10/cross-domain-ajax/ - 由于javascript是在两个网址之间共享的,我必须在wordpress端创建相同的文件codeigniter方面。 This means duplicate code, performance issues, and the fact that if the user is on the codeigniter side, the request has to make an extra page call to get the data. 这意味着重复的代码,性能问题,以及如果用户在codeigniter端,请求必须进行额外的页面调用以获取数据。
  3. Symbolic links - since both of these reside on the same server, is it possible to make a symbolic link on the wordpress side? 符号链接 - 因为它们都位于同一台服务器上,是否可以在wordpress端建立符号链接? Would my codeigniter settings be loaded? 我的codeigniter设置会被加载吗? I have a feeling this will not work. 我有一种感觉,这是行不通的。
  4. iFrame - This is a module being included, so it lacks all the styles and headers and whatnot iFrame - 这是一个包含的模块,所以它缺少所有的样式和标题等等
  5. .htaccess file - this is a long shot, but if there was some way to get the .htaccess file to redirect the call to the other server without ajax knowing, it might work? .htaccess文件 - 这是一个很长的镜头,但如果有一些方法可以让.htaccess文件将调用重定向到另一个服务器而不知道ajax,它可能有用吗?

At this point, I'm leaning to #2 because that's the only working solution. 在这一点上,我倾向于#2,因为这是唯一可行的解​​决方案。 Are there any other solutions that you guys could think of? 你们还有其他解决方案吗? If there was some way to pass data along with the jsonp, that would be ideal, but all sites say it's impossible to pass post data, and codeigniter doesn't like query strings... actually, I could enable it, but that would probably screw everything up at this point. 如果有一些方法可以将数据与jsonp一起传递,那将是理想的,但是所有站点都说不可能传递post数据,而codeigniter不喜欢查询字符串......实际上,我可以启用它,但那会可能在这一点上搞砸了一切。

UPDATE UPDATE

So I followed the first posters idea, and it worked. 所以我遵循了第一个海报的想法,它起作用了。 I found a similar solution at jQuery $.ajax(), $.post sending "OPTIONS" as REQUEST_METHOD in Firefox What worries me now is that they are say that there are some cross browser issues. 我在jQuery $ .ajax()发现了一个类似的解决方案,$ .post在Firefox中发送“OPTIONS”作为REQUEST_METHOD我现在担心的是他们说有一些跨浏览器问题。 Any thoughts? 有什么想法吗?

Would setting the HTTP header "Access-Control-Allow-Origin" in codeigniter site solve your problem? 在codeigniter站点中设置HTTP标头“Access-Control-Allow-Origin”可以解决您的问题吗? Something like this in your apache site configuration file could do the trick: apache站点配置文件中的类似内容可以解决问题:

    <Directory "/usr/lib/php-lib">
            Order allow,deny
            Allow from all
            Header set Access-Control-Allow-Origin "*"
    </Directory>

    #Instead of "*" you could restrict it to "www.mysite.com"

Or you could set this header inside an .htaccess file inside your page directory 或者,您可以在页面目录中的.htaccess文件中设置此标头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM