Skip to content

how to get the CI’s base url in JavaScript

Last updated on May 6, 2018

I received a tutorial request from my reader that asked me how to access CI’s base URL inside the JavaScript/external JavaScript files. Editing base URL of the project after each and every deployment is very frustrating and idiotic. There must be a better way to handle this base_url automatically into our js files. Yes, there is a better way, In this tutorial, I will show you most used trick. This trick is applicable to any framework or project.

how to get the CI’s base url in JavaScript

Just add the following code snippet in your master/main layout file, in the head section so that it can be accessible.

What we did – we just declared a JavaScript variable called base_url, that can later be used by external/inline javascript files(variable declaration should be top of all the files).

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments