CodeIgniter Forums

Full Version: calling base_url() or site_url() in the external js file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[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')
Pages: 1 2