[英]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:
以下是我在网上看到的解决方案,在我的情况下有缺点:
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不喜欢查询字符串......实际上,我可以启用它,但那会可能在这一点上搞砸了一切。
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.