CodeIgniter Forums
calling base_url() or site_url() in the external js file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: calling base_url() or site_url() in the external js file (/showthread.php?tid=58640)

Pages: 1 2


calling base_url() or site_url() in the external js file - El Forum - 07-05-2013

[eluser]xeroblast[/eluser]
sorry for a very late reply. my js script are external but im using the site_url() & base url() to that external script.

in your view header: include this script
Code:
<html>
<head>
<script type="text/javascript">
var js_site_url = function( urlText ){
var urlTmp = "<?php echo site_url('" + urlText + "'); ?>";
return urlTmp;
}
var js_base_url = function( urlText ){
var urlTmp = "<?php echo base_url('" + urlText + "'); ?>";
return urlTmp;
}
</script>
</head>
</html>
so when you need to call the site_url() or base_url() to your external js file, you just have to call js_site_url('codeigniter/url') or js_base_url('codeigniter/url')