Welcome Guest, Not a member yet? Register   Sign In
base_url() codeigniter 3.0.4 duplicate in URL with javascript
#1

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/...27)%20?%3E

please help me to resolve this..

thanks
Reply
#2

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB