3

I am trying to add an external javascript file to Codeigniter application.

I have placed my external js file in the "projectname/js/" folder.

Below is the script tag src in my view page. src="http://localhost/needpcbcodeigniter/js/registration.js">

But I am getting a "Not found" error for the js file.

2 Answers 2

2

Most probably this is because the apache mod_rewrite is dealing with the js folder as a codeigniter controller name (as if you're calling http://localhost/projectname/index.php/js/registration.js)

Check your .htaccess to make sure it doesn't redirect when a valid filename is requested. Check it here

Sign up to request clarification or add additional context in comments.

2 Comments

i am a newbie to codeignitor,where can i find the htaccess file in the installation folder?
You can't find it in the CI installation files..Create a new file and name it .htaccess in your project root manually.
0

You should add an external javascript file to codeigniter in assets folder.

You should check some following steps :-

1) first fix your project base_url which is set in application/config/config.php like-

$config['base_url'] = 'http://localhost/yourprojectname/'

2) create a folder(e.g: js) in assets folder(at root of folder) for save all javascript files(e.g : registration.js).

3) on final step where you want to use javascript file use code like this-

<script src="<?php echo base_url();?>/assets/js/registration.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.