Search code examples
phpjavascriptcodeigniterinclude-path

Code Igniter: Js file is included successfully, the script not working


I'm working on Code Igniter framework. I have a php file in:

C:\xampp\htdocs\MSPN\APPLICATION\views\Pengguna\yes.php

I also have js file in:

C:\xampp\htdocs\MSPN\TAMPILAN\js\yes.js

The base-url in the config.php:

$config['base_url'] = 'http://localhost/mspn';

When I tried:

<script src="<?php echo base_url('tampilan/js/yes.js'); ?>" type="text/javascript"></script>

When tried it in my browser, the script is not working. But when I checked the 'view-source' feature, and clicked on the link of that js, it pointed to the right file. So I guess the include function is correct.

I have done the $autoload['helper'] = array('url'); in autoload.php. And done this $this->load->helper('url'); in the controller file.

I did the include function for my css file, it worked. But it didn't for this js file. Now, I've finally given up to feel like I know what did I do wrong. So what have I missed? Thanks.


Solution

  • i am not expert in js but sometime i get this to, my experience check the script when load with firebug if run with firefox. if you see

    Failed to load resource: the server responded with a

    NetworkError: 404 Not Found - http://localhost/yourpath
    

    to fix this Try putting your main library calls in your header tag before you call all your resources.

    These should all still be in your header. Your document ready() stuff can stay in the footer. See if this fixes your issue.