Use base_url() function inside a jQuery script

1. In the template.php view or in your current view define a global variable in script:

<script type="text/javascript">

CI_ROOT = "<?php echo(base_url());?>";

</script>

With base_url you get the root url of your website.

2. Use the CI_ROOT in any js file to get the root url.
For example, in a jquery - ajax call:
...
$.post(CI_ROOT + 'bookings/updBooking_ByAjax', data, function(res){
alert(res);
...

No comments:

Post a Comment