I assume that I have the same scenario: for development, the site is available on localhost / cake, as a result of which the site is deployed in the root directory of example.com. In the header, I installed:
<base href="<?php echo $base_url ?>" /> ,
in AppContoller::beforeRender() I installed:
$this->set('base_url', 'http://'.$_SERVER['SERVER_NAME'].Router::url('/')); .
This works fine for everything except JS (thus AJAX) as it ignores base_url.
So I have a workaround (uses jQuery, but easy to replace without):
forUrl = function(url) { return $('base').attr('href')+url.substr(1); } login = function() { $.post(forUrl('/ajax/profileDiv'), $('#profile-login-form').serialize(), function(data) { (...) }); }
source share