views:

496

answers:

3

I know, strange title....

this is my problem:

I have the cakephp stack in /var/www/site

from one view under controller A I do a jquery ajax call:

$("#searchstring").autocomplete("/items/getitemsforautocomplete", {  ... more code

when the call is triggered I can see from firebug that cakephp wants to call:

http://localhost/items/getitemsforautocomplete?q=me

Note that 'site' is missing, resulting in a 404.

When I upload this to my site it works the way it should. How should I configure this correctly??

A: 

Doesn't '/' go to the root directory of the site? If your javascript file is in /var/www/site/script, you might want to do:

$("#searchstring").autocomplete("../items/getitemsforautocomplete", {  ... more code }
Gromer
Thanks - that did it (in only 11 min. - love the stack)
$("#searchstring").autocomplete("<?php echo $this->webroot; ?>items/getitemsforautocomplete", {-- does it also
A: 

Try using FULL_BASE_URL in your JS, like:

$("#searchstring").autocomplete("<?= FULL_BASE_URL ?>/items/getitemsforautocomplete", {

Not the most elegant way, but it solved some of my headaches in the past.

QAD
This should be right - but it does not work. First anserw does ;-)
A: 

this is most likely due to the level of the call made from jquery. is the http://localhost/items/... the correct URL?

a not-used html tag that is really good is setting the base href. then all links and javascript calls are made from this.

<base href="http://localhost/site/"&gt;

then just remove the leading '/' from your script

$("#searchstring").autocomplete("items/getitemsforautocomplete", {  ... more code
David Liddle
If I leave out the leading '/' cake will think that it should find the action Items in the current controller (called Shops) at post 'getitemsforautocomplete' as an argument.No good - but thanks though
Depends what you have set the base href. If it is as defined above jquery should call [http:/localhost/site/items/get..]
David Liddle