AJAX calls not happening when on www

Hey all, I’m having a weird problem with some jQuery $.post calls I’m making on a site I’m developing.
I haven’t encountered this problem before but for some reason my AJAX calls don’t happen when I’m on the www. ‘sub’-domain.
When I looked it up I found answers saying I should use relative paths, which I always do, but my calls don’t work with either absolute, relative or a combination (relative starting with a backslash) of those.

Firebug doesn’t show the call, an alert(); confirms the function does get called.

(One of) my ajax functions:

function cart_add(id,amount){

	$.post('ajax/cart_action.php',{action: 'add', id: id, amount: amount,unique: new Date().getTime()},function(data){

Works like a charm when I’m on the domain site.com, but not at all when on www.site.com.

What happens when you try to manually navigate to:

instead of:

Nothing, because the script doesn’t actually return anything.
It does end up at the correct file however.
There were some DNS problems at first but those have been fixed last week and I can’t imagine that still influencing the calls (esp since I send a timestamp to prevent caching).

When setting the path to the absolute htp://www.site.com/ajax/cart_action.php it works (as long as I’m on the www. domain).

It does sound like there’s some kind of cross-domain trouble that’s occurring, but as to an actual solution, that’s tricky to resolve without being able to experiment.

Perhaps this entry might help: http://ejohn.org/blog/cross-site-xmlhttprequest/

Or maybe: http://forum.jquery.com/topic/how-can-i-use-post-or-get-from-subdomain

However, a proper solution might lie in the server configuration for the www domain instead.

That second link helped me!

I make use of a <base href> tag to avoid htaccess url rewrite problems without resorting to absolute paths (because I test in a subfolder I’d have to change all the links after the site goes live).

I should really start working on a testserver instead so I don’t have to use base href anymore, but with that little bit of javascript I got it working.