Reputation: 2989
I want to be able to upload my CakePHP (2.4) app to whichever folder on whichever server and the ajax calls still work without having to go through and change the javascript manually on each page. I have found some answers to this question but they are not truly generalized solutions. They only work for the questioner's specific problem. I want a solution that I can use for my entire web-developing career. None of the CakePHP constants seem to do the trick. Is there something I can do right now so that I never have to worry about manually changing URLs ever again?
For example, in my javascript I want to be able to write something like
$.ajax({'url':'<?php echo MY_ROOT?>/controller/action'})
.done(function(result){/*etc.*/})
There are some built-in constants that seem like they should work on first glance but none of them work the same on my localhost as on my web server, so I keep having to manually change things every time I upload to my web server from my localhost.
Thanks!
Upvotes: 0
Views: 78
Reputation: 449
Try
$.ajax(
{
'url':"<?php echo $this->Html->url(array('controller'=>'your_controller','action'=>'your_action'));?>"
})
.done(function(result){/*etc.*/})
Upvotes: 1