0

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.

Here's the situation. I have two urls, www.mysite.com and 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. 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. 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. 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.
  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. 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.
  3. Symbolic links - since both of these reside on the same server, is it possible to make a symbolic link on the wordpress side? Would my codeigniter settings be loaded? 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
  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?

At this point, I'm leaning to #2 because that's the only working solution. 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.

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. Any thoughts?

Community
  • 1
  • 1
JohnathanKong
  • 1,307
  • 3
  • 21
  • 36

1 Answers1

2

Would setting the HTTP header "Access-Control-Allow-Origin" in codeigniter site solve your problem? Something like this in your apache site configuration file could do the trick:

    <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

Toni Rosa
  • 318
  • 1
  • 3
  • 8
  • can I put this into my .htaccess file? – JohnathanKong Jan 10 '11 at 00:55
  • Did some research on it, and it works on firefox! I didn't put it into my configuration file, I actually put it into the header of the page. Please read update. – JohnathanKong Jan 10 '11 at 01:06
  • I am glad my answer helped you, regarding the jquery ajax calls, I don't see they wouldn't honour the 'Access-Control-Allow-Origin' header... and as I'm writting this comment while reading the link you provided in your UPDATE, the 2nd answer (the one by Mike C) seems to indicate what I was saying... It should work :) – Toni Rosa Jan 10 '11 at 15:45