开发者

How to use Code Igniter to show Dynamic images via javascript(jQuery)

开发者 https://www.devze.com 2022-12-24 05:43 出处:网络
You can use the URL helper in Code Igniter to load CSS and Javascript with the base_url() method, but what if you have images dynamically being placed into your HTML via javascript? for example in my

You can use the URL helper in Code Igniter to load CSS and Javascript with the base_url() method, but what if you have images dynamically being placed into your HTML via javascript? for example in my javascript file I've got

var arrowimages={down:['downarrowclass', 'images/down.png', 23], right:['rightarrowclass', 'images/right.png']}

and those images will be placed into whatever menu item I've specified has a drop down menu.

but that file is a .js file so obviously the server won't load php inside of it.

so, how can I set the base ur开发者_StackOverflow社区l for the JS?

Thanks!

-Aaron


Define a constant javascript variable like BASE_URI in the of your view, you can then reference this variable in any of your external javascript files.

<head>
....
<script type="text/javascript">
    var BASE_URI = "<?php echo base_url(); ?>";
</script>
....
</head>

External js...

var arrowimages={down:['downarrowclass', BASE_URI+'images/down.png', 23], right:['rightarrowclass', BASE_URI+'images/right.png']}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号