How can I make sure the path in jQuery autocomplete to CakePHP controller / action is resolved correctly?

I have a CakePHP stack at / var / www / site

from one view under controller A I am making a jQuery ajax call:

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

      

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

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

      

Note that there is no "site", resulting in a 404.

When I upload this to my site, it works as it should. How do I set this up correctly?

0


a source to share


3 answers


Does the '/' go to the root of the site? If your javascript file is located at / var / www / site / script, you might want to do:



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

      

0


a source


Try using FULL_BASE_URL in your JS like:

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

      



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

0


a source


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

The unused html tag, which is really good, sets the base href. then all links and javascript calls are made from this.

<base href = "http: // localhost / site /">

then just remove the leading '/' from your script

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


a source







All Articles