I am working on an application which is running in CakePHP and I am using AJAX queries from within.
In all the cases for all the ajax post i have used the url as
var ht = $.ajax({
type: "GET",
url: "http://172.20.52.99/FormBuilder/index.php/forms/viewChoices/"+attribute_id,
async: false
}).responseText;
var myObject = eval('(' + ht + ')');
Is there any way in CakePHP where I can give my base URL as http://172.20.52.99/FormBuilder/index.php/
and to call the base URL in all the places I want.
I assume I've the same scenario: for development, the site is available at localhost/cake, whereby in production the site is deployed in the root dir of example.com. In the header I set:
<base href="<?php echo $base_url ?>" />
,in
AppContoller::beforeRender()
I set:$this->set('base_url', 'http://'.$_SERVER['SERVER_NAME'].Router::url('/'));
.This works fine for everything, except JS (so thus AJAX), as it ignores base_url.
Therefore I have a workaround (uses jQuery, but easy to substitute without):