Relative vs. absolute urls in jQuery AJAX requests
ajax, javascript, jquery, php
Solution
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.
Problem
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://example.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://example.com/index.php', {id: 1234, action: 1, step: 1}, function(data) { /* something */ }); ``` Can anybody explain why AJAX requests behave in this way? x_X