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

[eluser]Zied[/eluser]
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',

Thinks
#2

[eluser]steelaz[/eluser]
You can set base url for the whole website by adding <base> tag in your header section:

Code:
<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:

Code:
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.
#3

[eluser]Zied[/eluser]
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.
#4

[eluser]steelaz[/eluser]
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.
#5

[eluser]Zied[/eluser]
It's the same problem,
The project is on local host now, I will upload it and send you the URL page
Thinks
#6

[eluser]umefarooq[/eluser]
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

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

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

in yourjs.js file

alert(base_url)

removed is <script>
#7

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

Try to use

Code:
<? = site_url(); ?>

instead of base_url();

On my js I use that, and works well.
#8

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

Code:
<head>

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

[removed]
    //<![CDATA[
        var BASE_URL = "<?php echo base_url(); ?>";
    //]]>
[removed]

</head>

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB