CodeIgniter Forums

Full Version: base_url() codeigniter 3.0.4 duplicate in URL with javascript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have source code in config.php
PHP Code:
$config['base_url'] = 'http://localhost/metter/'

I have source code in autoload.php
PHP Code:
$autoload['helper'] = array('url','file','form','html','date'); 

I have script with ajax
Code:
   $("#save").click(function(){
       $.ajax({
           type    : 'POST',
           url     : 'save', // if I use '<?php echo base_url();?>' + 'master/Category/save' must error
           data    : $('#form_add').find('input, select, textarea, button').serialize(),
           cache   : false,
           success : function(result){
               window.location="<?php echo base_url('master/Catagory') ?>";
           }
       });
       return false;
   });

process save in php is successfully, but in window.location="....." on URL is
http://localhost/metter/master/Category/%3C?php%20echo%20base_url(%27master/Catagory%27)%20?%3E

please help me to resolve this..

thanks
your script is in a file with extension php or js ?

because <?php ... ?> can work only on php files Smile

for me, before insert all my JS scripts in my template, i write this little code

PHP Code:
<script>
    var 
BASE_URL "<?php echo base_url(); ?>";
<
script>

<
script type="text/javascript" src="file1.js" />
<
script type="text/javascript" src="file2.js" />
<
script type="text/javascript" src="file3.js" />
..... 

BASE_URL will be available in all your JS files