Welcome Guest, Not a member yet? Register   Sign In
base_url () in JS file

How I can to execute base_url () in js file?
I have problem to call images files in lightbox.js, the links are wrong and the photos is not appeared.

fileLoadingImage: 'images/lightbox/lightbox/loading.gif',


You can set base url for the whole website by adding <base> tag in your header section:

<base href="<?= base_url(); ?>"/>

So if your application resides in http://www.example.com/app/ and you call for assets (css, images, js) using relative path as in your example:

fileLoadingImage: ‘images/lightbox/lightbox/loading.gif’,

Browser will actually look for it in http://www.example.com/app/images/lightb...oading.gif

You can check the path browser is trying to access by loading Firebug.

is the same problem.
when I used Firebug, I found that (<base href="<?= base_url(); ?>"/&gtWink exist, but in gray color, and the link is the same.

When in Firebug, open "Net" tab, then "All" and refresh your page. Assets that can't be fetched will be in red and should give you a clue where the problem is. Also if it's possible, it would help if you could post a link to the page you're working on.

It's the same problem,
The project is on local host now, I will upload it and send you the URL page

just define a global base_url in you html page or template before your scripts to call you can in your all js script files

in you html page or template file just define once before scripts
var base_url = "<?=base_url()?>";

<script src="yourjs.js"><script/>

in yourjs.js file


removed is <script>

[eluser]Caio Russo[/eluser]
hi Zied,

Try to use

<? = site_url(); ?>

instead of base_url();

On my js I use that, and works well.

Try this, replace [removed] tags with you know what.


<base href="<?php echo base_url(); ?>"/>

        var BASE_URL = "<?php echo base_url(); ?>";



Theme © iAndrew 2016 - Forum software by © MyBB