Fellow Coders,
so far I have been using the CI url helper to build full urls using base_url() and site_url(). Now I’m trying to access a controller function within some javascript code that will be loaded as a js file.
it’s actually an ajax call with a url parameter that should be something like:
url : '/account/check_user'
now unless i prefix the url with the full path as ins http://servername/….. the code fails.
all the code examples i’ve seen use the short version of the url but i cannot get it to work. I’m sure this is really simple but i’m stuck.
i could pass a hidden form field to the js code but i’d rather not. any ideas?
thanks
Well, I also tend to use absolute URLs and a good practice I always do is declaring a JS variable:
In:
headsectionscripttagmain.jsfile that holds most of my JS code AND it’s always included in my views, then I put that line first thing in the file.After that, you use it like:
Anyway, the first slash
/in your url tells the browser to go to the URL root which would not be the right place to put your url chunk in! for example:if your CI installation is in
cifolder and your URL is:domain.com/ci/contorller/method/Then your URL will become:
domain.com/contorller/method/!!