views:

588

answers:

1

hey there,

I'm having a hard time getting my AJAX requests to work on a staging server. It all worked fine on my development machine, but as soon as I uploaded it, all my AJAX requests stopped working. I found out that, if I change the relative urls (eg. "index.php") to absolute urls ("http://mydomain.com/index.php") the requests work again, but I do not understand why.

Example request:

jQuery.post('index.php', {id: 1234, action: 1, step: 1}, function(data) { // something });

This does not work, I does not even show up in the firebug console. The success handler is called though, which is very confusing.

This works just fine:

jQuery.post('http://mydomain.com/index.php', {id: 1234, action: 1, step: 1}, function(data) { // something });

Can anybody explain why AJAX requests behave in this way? x_X

+1  A: 

Try adding a / before index.php in your first example to force it to look from root. Double check to make sure your directory-structures are exactly the same with regards to where index.php is.

Jonathan Sampson
If this was the problem, shouldn't I get a 404 response then? In my case, the request doesn't even show up in firebug... that's the weird thing... I'll give it a try with the / though.
x3ro
Without knowing more about your project, I can't say.
Jonathan Sampson