SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: XMLHttpRequest and subdomains
-
Jun 24, 2007, 09:41 #1
- Join Date
- Jun 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
XMLHttpRequest and subdomains
I had just gotten subdomains to work (username.domain.com) and then realized my Ajax scripts weren't doing that good anymore.
I read that XMLHttpRequest can't access other domains, but shouldn't there be a simple(r) way to make it work with subdomains?
I'm pretty much a javascript newbie but decent with PHP.
Is there a painless way to make this all work again? Or any other way?
Here's a bit of the code;
Code JavaScript:var cururl = 'http://domain.com/'; function createRequestObject() { var req; if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert('Problem creating the XMLHttpRequest object'); } return req; } function handleDivTag(divtag) { var divtag; return divtag; } var http = createRequestObject(); var divhandler = new handleDivTag(null); function sendRequest(ua_id,show,series) { http.open('get', cururl+'status.php?ua_id='+ua_id+'&show='+show+'&series='+series+'&dummy=' + new Date().getTime()); http.onreadystatechange = handleResponseTwo; divhandler.divtag = ua_id; http.send(null); } function handleResponseTwo() { if (http.readyState == 4 && http.status == 200) { var response = http.responseText; if (response) { document.getElementById('editinfo'+divhandler.divtag).innerHTML = response; } } }
-
Jun 24, 2007, 18:27 #2
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Can you make your script accessible from the subdomains (a symlink on the file system perhaps)? That'd be the easiest way, since the cross-site scripting restrictions are imposed by the browsers, which are out of our control.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Jun 25, 2007, 01:57 #3
- Join Date
- Jun 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Would you please give a bit more info on how I could use that, I looked it up and I guess it's not as easy as just writing symlink(http://domain.com,currentuser.domain.com) in the PHP file where the the sendRequest() links are located? I guess I can't use absoulte paths in symlink tho. And these are wilcard subdomains, so they aren't connected to a specific folder on the server, if I have understood everthing right that is...
I'm on regular webhosting so I don't think I have the rights to go very deep in the configuration.
I also tried do solve this with htaccess which I read about in an article;
RewriteRule ^/call/(.*)$ http://domain.com/$1 [P]
Placing the status.php file (which is called by the .js file in my first post) in the /call/ directory. Didn't work tho...
-
Jun 26, 2007, 08:54 #4
- Join Date
- Jun 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
If I understand symlink correctly, it's something which is just created after having run the command?
Would something like this work perhaps?
PHP Code:symlink( "./",
"/home/web2753/domains/domain.com/public_html/");
Do you know if symlink is a method which can make this all work? I couldn't really find anything useful when I googled on it (and xmlhttprequest). I've only found methods which seemed to require a lot of rewriting and adding of new javascripts, curl and what notAnd the above RewriteRule which failed and also ProxyPass which seem to require httpd.conf access.
I can understand that fetching from other domains/sites should be quite tricky, but I'm leeching off of myself here, so to speakWell, maybe I should just stop whining and drop the subdomains idea, not vital but would probably be an appreciated feature.
-
Jun 26, 2007, 09:31 #5
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I was referring to creating a symlink on the file system, not any PHP code, and not anything specific to XMLHttpRequest. A symbolic link is like creating a virtual file which is updated whenever the original changes. By creating a symlink to this script you're accessing in each subdomain's directory on the file system, it'd be accessible at an address under the subdomain, so that your XMLHttpRequest can hit a copy on the same domain as the javascript is running, avoiding domain restrictions.
Look up "ln -s".Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Jun 27, 2007, 03:14 #6
- Join Date
- Jun 2007
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah, I see..
Ok, so I tried a couple of ln -s'es but I can't figure out where to create this symlink. As I don't really have any directories (they are wildcard subdomains).
Tried this for example;
Code:ln -s /home/web2753/domains/domain.com/public_html/ajax/status.php
This created a symlink for status.php in he same directory as /domain.com/ lies in, and also did the same in the /domain.com/public_html/ directory. This was probably wrong but...
I also tried setup a directory called /test/ in /public_html/, did the above symlink in /test/, and then tried while entering test.domain.com, but that didn't work either.
Bookmarks