[Solved] Setting url in a .js file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: [Solved] Setting url in a .js file (/showthread.php?tid=66538) |
[Solved] Setting url in a .js file - wolfgang1983 - 11-01-2016 I have set my url in a js file Code: assets And I have a controller called Filemanager.php Code: application When I try click on my button which trys to launch modal. It gives the wrong location and a 404 error The url out puts Code: http://localhost/project-1/question/filemanager How ever should only produce Code: http://localhost/project-1/filemanager assets > jquery > common.js Code: $(document).ready(function() { Routes.php Code: $route['filemanager'] = 'filemanager/index'; Any idea in how to make sure it gets the right url I cannot use base_url in a js file. RE: Setting url in a .js file - salain - 11-01-2016 As a work around I have a view that is use in every pages. The view is to set default styles and Javascript for the site. This include a JavaScript variable for the site URL PHP Code: <script type="text/javascript"> Then use the variable to make the URL Code: $(document).ready(function() { I hope this helps. RE: Setting url in a .js file - wolfgang1983 - 11-02-2016 (11-01-2016, 10:45 PM)salain Wrote: As a work around I have a view that is use in every pages. I can access the url in browser but when use ajax says network error even though url is correct now. RE: Setting url in a .js file - salain - 11-02-2016 I never had any issues but I have no route setup for url I use with ajax. Maybe ajax by pass the route, but that being said it should work as the index method is default. Sorry, I don't know what could be the problem. RE: Setting url in a .js file - InsiteFX - 11-02-2016 PHP Code: <script type="text/javascript"> RE: Setting url in a .js file - wolfgang1983 - 11-02-2016 (11-02-2016, 03:07 AM)InsiteFX Wrote: Your one worked plus on common.js miss spelt also filemanager so both now are fixed. RE: Setting url in a .js file - InsiteFX - 11-02-2016 (11-02-2016, 03:20 AM)wolfgang1983 Wrote:(11-02-2016, 03:07 AM)InsiteFX Wrote: You can also do the same using site_url if you need the index.php |