Welcome Guest, Not a member yet? Register   Sign In
Javascript issue

In this thread I asked about setting up 'fake' subdomains for users. Here's the .htaccess I wound up with:

RewriteEngine on

# Prevent infinite loop
rewriteCond $1 !^index.php/user/show/

RewriteCond %1 !^www$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.database\.com
RewriteCond %1 !^www$ [NC]
RewriteRule (.*) index.php/user/show/%1/$1 [L]

RewriteCond $1 !^(index\.php|images|robots\.txt|css|js|img|uploads|avatars)
RewriteRule ^(.*)$ /index.php/$1 [L]

This works well. Except for when I come to carry out an Ajax query (I use the Mootools library).Basically, I have a function which generates an Ajax request:

function fetch_latest_entries() {

   new Ajax('fetch', {
    method: 'get',
        onComplete: function() {

        // yadda yadda



This works great when I call it from domain.com/account. However, I assign each user on my site their own subdomain, like so: username.domain.com. Within cPanel I've setup *.domain.com to point towards domain.com/user/view/{username}.

When I execute the above function from username.domain.com, Firebug returns the following:

Quote:[Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "" data: no]

However, when I run the query from domain.com, it works fine. A little snooping around on Google has led me to believe that this is because the XMLHttpRequest considers a subdomain and a domain to be different locations. To solve this I imagine I have to send the request to username.domain.com/fetch rather than domain.com/fetch. But the above .htaccess doesn't allow this.

Any suggestions?

Your assumptions about the xmlhttprequest are right. A subdomain and normal domain are indeed two different locations and for security reasons, ajax can't make a call from one to the other.

However. I read smth today that might do the trick for you. Sucks it's slipping my mind atm though. Flickr uses it to make calls to their api.

When googling, I stumbled upon this:

Might be an interesting read for you Wink

I was hoping there'd be a simple solution as username.domain.com is not actually a physical subdomain, but rather sends the user to domain.com/users/view.

[eluser]Sarfaraz Momin[/eluser]
I did this actually but for categories and I did not use .htaccess for it since it complicates the whole structure. Instead I used CI routes to achieve the task. Please check the post here http://ellislab.com/forums/viewthread/61799/P15/. This could lead you in some correct direction.

have a good day !!!


[quote author="Crimp" date="1212322567"]Use JSONP?[/quote]

That's what it was called! I believe it's mentioned in the link I posted a few posts up too. However, I like Sarfaraz Momin's idea too!

Theme © iAndrew 2016 - Forum software by © MyBB